GeezerVison is showing github.com — src: stop copying code cache · nodejs/node@a11507e
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/node.h +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -505,6 +505,9 @@ struct IsolateSettings { |
505 | 505 | // feature during the build step by passing the --disable-shared-readonly-heap |
506 | 506 | // flag to the configure script. |
507 | 507 | // |
| 508 | +// The snapshot *must* be kept alive during the execution of the Isolate |
| 509 | +// that was created using it. |
| 510 | +// |
508 | 511 | // Snapshots are an *experimental* feature. In particular, the embedder API |
509 | 512 | // exposed through this class is subject to change or removal between Node.js |
510 | 513 | // versions, including possible API and ABI breakage. |
|
Collapse file
Copy file name to clipboardExpand all lines: src/node_builtins.cc +10-6Lines changed: 10 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -501,13 +501,17 @@ void BuiltinLoader::CopyCodeCache(std::vector<CodeCacheInfo>* out) const { |
501 | 501 |
|
502 | 502 | void BuiltinLoader::RefreshCodeCache(const std::vector<CodeCacheInfo>& in) { |
503 | 503 | RwLock::ScopedLock lock(code_cache_->mutex); |
| 504 | + code_cache_->map.reserve(in.size()); |
| 505 | + DCHECK(code_cache_->map.empty()); |
504 | 506 | for (auto const& item : in) { |
505 | | - size_t length = item.data.size(); |
506 | | - uint8_t* buffer = new uint8_t[length]; |
507 | | - memcpy(buffer, item.data.data(), length); |
508 | | - auto new_cache = std::make_unique<v8::ScriptCompiler::CachedData>( |
509 | | - buffer, length, v8::ScriptCompiler::CachedData::BufferOwned); |
510 | | - code_cache_->map[item.id] = std::move(new_cache); |
| 507 | + auto result = code_cache_->map.emplace( |
| 508 | + item.id, |
| 509 | + std::make_unique<v8::ScriptCompiler::CachedData>( |
| 510 | + item.data.data(), |
| 511 | + item.data.size(), |
| 512 | + v8::ScriptCompiler::CachedData::BufferNotOwned)); |
| 513 | + USE(result.second); |
| 514 | + DCHECK(result.second); |
511 | 515 | } |
512 | 516 | code_cache_->has_code_cache = true; |
513 | 517 | } |
|