Skip to content

Commit e7c2863

Browse files
agape1225aduh95
authored andcommitted
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> PR-URL: #65453 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent cde19de commit e7c2863

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

src/node_snapshotable.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,17 +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.
1578-
LocalVector<String> parameters(
1579-
isolate,
1580-
{
1581-
FIXED_ONE_BYTE_STRING(isolate, "require"),
1582-
FIXED_ONE_BYTE_STRING(isolate, "__filename"),
1583-
FIXED_ONE_BYTE_STRING(isolate, "__dirname"),
1584-
});
1579+
LocalVector<String> parameters(isolate,
1580+
{
1581+
env->require_string(),
1582+
env->__filename_string(),
1583+
env->__dirname_string(),
1584+
});
15851585

15861586
ScriptOrigin script_origin(filename, 0, 0, true);
15871587
ScriptCompiler::Source script_source(source, script_origin);

0 commit comments

Comments
 (0)