diff --git a/src/node_i18n.cc b/src/node_i18n.cc index 43bb68351bf0a6..91052b6d14b5f7 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -287,6 +287,14 @@ void Transcode(const FunctionCallbackInfo&args) { const enum encoding toEncoding = ParseEncoding(isolate, args[2], BUFFER); if (SupportedEncoding(fromEncoding) && SupportedEncoding(toEncoding)) { + // If encodings are the same then there is nothing to transcode and we can + // just copy the buffer + if (fromEncoding == toEncoding) { + MaybeStackBuffer stackbuf(input.length()); + memcpy(stackbuf.out(), input.data(), input.length()); + args.GetReturnValue().Set(Buffer::New(env, &stackbuf).ToLocalChecked()); + return; + } TranscodeFunc tfn = &Transcode; switch (fromEncoding) { case ASCII: