buffer: cache Environment::GetCurrent to avoid repeated calls

PR-URL: https://github.com/nodejs/node/pull/59043
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: theanarkh <theratliter@gmail.com>
Reviewed-By: Dario Piotrowicz <dario.piotrowicz@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
This commit is contained in:
Mert Can Altin 2025-07-26 19:35:47 +03:00 committed by GitHub
parent 6ea421a3d3
commit 5e1a4fa3e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1061,8 +1061,9 @@ void IndexOfBuffer(const FunctionCallbackInfo<Value>& args) {
enum encoding enc = static_cast<enum encoding>(args[3].As<Int32>()->Value());
THROW_AND_RETURN_UNLESS_BUFFER(Environment::GetCurrent(args), args[0]);
THROW_AND_RETURN_UNLESS_BUFFER(Environment::GetCurrent(args), args[1]);
Environment* env = Environment::GetCurrent(args);
THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]);
THROW_AND_RETURN_UNLESS_BUFFER(env, args[1]);
ArrayBufferViewContents<char> haystack_contents(args[0]);
ArrayBufferViewContents<char> needle_contents(args[1]);
int64_t offset_i64 = args[2].As<Integer>()->Value();