Skip to content

Commit 77bfbd4

Browse files
committed
sea: pass code cache data as an external buffer to JS
Otherwise, we were unnecessarily creating an additional copy. Signed-off-by: Darshan Sen <raisinten@gmail.com>
1 parent dc8bca5 commit 77bfbd4

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

src/node_sea.cc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,19 @@ void GetCodeCache(const FunctionCallbackInfo<Value>& args) {
191191

192192
SeaResource sea_resource = FindSingleExecutableResource();
193193

194-
Local<Object> buf =
195-
Buffer::Copy(
196-
env,
197-
reinterpret_cast<const char*>(sea_resource.code_cache.data()),
198-
sea_resource.code_cache.length())
199-
.ToLocalChecked();
194+
Local<Object> buf;
195+
if (!Buffer::New(
196+
env,
197+
const_cast<char*>(sea_resource.code_cache.data()),
198+
sea_resource.code_cache.length(),
199+
[](char* /* data */, void* /* hint */) {
200+
// We don't free the code cache data string because it is not owned
201+
// by us.
202+
},
203+
nullptr)
204+
.ToLocal(&buf)) {
205+
return;
206+
}
200207

201208
args.GetReturnValue().Set(buf);
202209
}

0 commit comments

Comments
 (0)