Skip to content

Commit 9af9206

Browse files
committed
src: optimize buffer transcode for matching encodings
1 parent e70bd47 commit 9af9206

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/node_i18n.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,14 @@ void Transcode(const FunctionCallbackInfo<Value>&args) {
287287
const enum encoding toEncoding = ParseEncoding(isolate, args[2], BUFFER);
288288

289289
if (SupportedEncoding(fromEncoding) && SupportedEncoding(toEncoding)) {
290+
// If encodings are the same then there is nothing to transcode and we can
291+
// just copy the buffer
292+
if (fromEncoding == toEncoding) {
293+
MaybeStackBuffer<char> stackbuf(input.length());
294+
memcpy(stackbuf.out(), input.data(), input.length());
295+
args.GetReturnValue().Set(Buffer::New(env, &stackbuf).ToLocalChecked());
296+
return;
297+
}
290298
TranscodeFunc tfn = &Transcode;
291299
switch (fromEncoding) {
292300
case ASCII:

0 commit comments

Comments
 (0)