Skip to content

Commit 97f69fe

Browse files
committed
src: reuse cached strings in CompileSerializeMain
CompileSerializeMain() created new "require", "__filename", and "__dirname" strings via FIXED_ONE_BYTE_STRING() on every call, even though these strings are already cached on IsolateData/Environment as require_string(), __filename_string(), and __dirname_string() (defined via PER_ISOLATE_STRING_PROPERTIES in src/env_properties.h) and are reused this way elsewhere (e.g. the sibling RunEmbedderPreload() already obtains Environment* the same way). Signed-off-by: agape1225 <49804691+agape1225@users.noreply.github.com>
1 parent 21f0f27 commit 97f69fe

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎src/node_snapshotable.cc‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,16 +1571,17 @@ void CompileSerializeMain(const FunctionCallbackInfo<Value>& args) {
15711571
CHECK(args[0]->IsString());
15721572
Local<String> filename = args[0].As<String>();
15731573
Local<String> source = args[1].As<String>();
1574+
Environment* env = Environment::GetCurrent(args);
15741575
Isolate* isolate = args.GetIsolate();
15751576
Local<Context> context = isolate->GetCurrentContext();
15761577
// TODO(joyeecheung): do we need all of these? Maybe we would want a less
15771578
// internal version of them.
15781579
LocalVector<String> parameters(
15791580
isolate,
15801581
{
1581-
FIXED_ONE_BYTE_STRING(isolate, "require"),
1582-
FIXED_ONE_BYTE_STRING(isolate, "__filename"),
1583-
FIXED_ONE_BYTE_STRING(isolate, "__dirname"),
1582+
env->require_string(),
1583+
env->__filename_string(),
1584+
env->__dirname_string(),
15841585
});
15851586

15861587
ScriptOrigin script_origin(filename, 0, 0, true);

0 commit comments

Comments
 (0)