Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kvakil committed Mar 15, 2023
1 parent 8aeb303 commit 49d7ab5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
24 changes: 11 additions & 13 deletions src/node_builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,7 @@ void BuiltinLoader::AddExternalizedBuiltin(const char* id,
{
Mutex::ScopedLock lock(externalized_builtins_mutex);
auto it = externalized_builtin_sources.find(id);
if (it != externalized_builtin_sources.end()) {
// OK to get the raw pointer, since externalized_builtin_sources owns
// the resource, resources are never removed from the map, and
// externalized_builtin_sources has static lifetime.
resource = it->second.get();
} else {
if (it == externalized_builtin_sources.end()) {
std::string source;
int r = ReadFileSync(&source, filename);
if (r != 0) {
Expand All @@ -247,14 +242,17 @@ void BuiltinLoader::AddExternalizedBuiltin(const char* id,
reinterpret_cast<char16_t*>(out->data()));
out->resize(u16_length);

auto resource_ptr = std::make_unique<StaticExternalTwoByteResource>(
out->data(), out->size(), out);
// OK to get the raw pointer, since externalized_builtin_sources owns
// the resource, resources are never removed from the map, and
// externalized_builtin_sources has static lifetime.
resource = resource_ptr.get();
externalized_builtin_sources[id] = std::move(resource_ptr);
auto result = externalized_builtin_sources.emplace(
id,
std::make_unique<StaticExternalTwoByteResource>(
out->data(), out->size(), out));
CHECK(result.second);
it = result.first;
}
// OK to get the raw pointer, since externalized_builtin_sources owns
// the resource, resources are never removed from the map, and
// externalized_builtin_sources has static lifetime.
resource = it->second.get();
}

Add(id, UnionBytes(resource));
Expand Down
2 changes: 1 addition & 1 deletion src/node_union_bytes.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class UnionBytes {
UnionBytes(UnionBytes&&) = default;
UnionBytes& operator=(UnionBytes&&) = default;

bool IsOneByte() const { return one_byte_resource_ != nullptr; }
bool is_one_byte() const { return one_byte_resource_ != nullptr; }

v8::Local<v8::String> ToStringChecked(v8::Isolate* isolate) const;

Expand Down
2 changes: 1 addition & 1 deletion src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ void SetConstructorFunction(Isolate* isolate,
}

Local<String> UnionBytes::ToStringChecked(Isolate* isolate) const {
if (IsOneByte()) {
if (is_one_byte()) {
return String::NewExternalOneByte(isolate, one_byte_resource_)
.ToLocalChecked();
} else {
Expand Down
4 changes: 2 additions & 2 deletions test/cctest/test_per_process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ namespace {
TEST_F(PerProcessTest, EmbeddedSources) {
const auto& sources = PerProcessTest::get_sources_for_test();
ASSERT_TRUE(std::any_of(sources.cbegin(), sources.cend(), [](auto p) {
return p.second.IsOneByte();
return p.second.is_one_byte();
})) << "BuiltinLoader::source_ should have some 8bit items";

ASSERT_TRUE(std::any_of(sources.cbegin(), sources.cend(), [](auto p) {
return !p.second.IsOneByte();
return !p.second.is_one_byte();
})) << "BuiltinLoader::source_ should have some 16bit items";
}

Expand Down

0 comments on commit 49d7ab5

Please sign in to comment.