Skip to content

Commit

Permalink
sea: pass code cache data as an external buffer to JS
Browse files Browse the repository at this point in the history
Otherwise, we were unnecessarily creating an additional copy.

Signed-off-by: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
RaisinTen committed May 27, 2023
1 parent 05199d8 commit d17be31
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/node_sea.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,19 @@ void GetCodeCache(const FunctionCallbackInfo<Value>& args) {

SeaResource sea_resource = FindSingleExecutableResource();

Local<Object> buf =
Buffer::Copy(
env,
reinterpret_cast<const char*>(sea_resource.code_cache.data()),
sea_resource.code_cache.length())
.ToLocalChecked();
Local<Object> buf;
if (!Buffer::New(
env,
const_cast<char*>(sea_resource.code_cache.data()),
sea_resource.code_cache.length(),
[](char* /* data */, void* /* hint */) {
// We don't free the code cache data string because it is not owned
// by us.
},
nullptr)
.ToLocal(&buf)) {
return;
}

args.GetReturnValue().Set(buf);
}
Expand Down

0 comments on commit d17be31

Please sign in to comment.