mirror of https://github.com/nodejs/node.git
src: optimize buffer transcode for matching encodings
This commit is contained in:
parent
e70bd47da9
commit
9af9206b4d
|
@ -287,6 +287,14 @@ void Transcode(const FunctionCallbackInfo<Value>&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<char> 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:
|
||||
|
|
Loading…
Reference in New Issue