Skip to content

Commit 49d7ab5

Browse files
committed
review comments
1 parent 8aeb303 commit 49d7ab5

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

src/node_builtins.cc

+11-13
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,7 @@ void BuiltinLoader::AddExternalizedBuiltin(const char* id,
223223
{
224224
Mutex::ScopedLock lock(externalized_builtins_mutex);
225225
auto it = externalized_builtin_sources.find(id);
226-
if (it != externalized_builtin_sources.end()) {
227-
// OK to get the raw pointer, since externalized_builtin_sources owns
228-
// the resource, resources are never removed from the map, and
229-
// externalized_builtin_sources has static lifetime.
230-
resource = it->second.get();
231-
} else {
226+
if (it == externalized_builtin_sources.end()) {
232227
std::string source;
233228
int r = ReadFileSync(&source, filename);
234229
if (r != 0) {
@@ -247,14 +242,17 @@ void BuiltinLoader::AddExternalizedBuiltin(const char* id,
247242
reinterpret_cast<char16_t*>(out->data()));
248243
out->resize(u16_length);
249244

250-
auto resource_ptr = std::make_unique<StaticExternalTwoByteResource>(
251-
out->data(), out->size(), out);
252-
// OK to get the raw pointer, since externalized_builtin_sources owns
253-
// the resource, resources are never removed from the map, and
254-
// externalized_builtin_sources has static lifetime.
255-
resource = resource_ptr.get();
256-
externalized_builtin_sources[id] = std::move(resource_ptr);
245+
auto result = externalized_builtin_sources.emplace(
246+
id,
247+
std::make_unique<StaticExternalTwoByteResource>(
248+
out->data(), out->size(), out));
249+
CHECK(result.second);
250+
it = result.first;
257251
}
252+
// OK to get the raw pointer, since externalized_builtin_sources owns
253+
// the resource, resources are never removed from the map, and
254+
// externalized_builtin_sources has static lifetime.
255+
resource = it->second.get();
258256
}
259257

260258
Add(id, UnionBytes(resource));

src/node_union_bytes.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class UnionBytes {
6565
UnionBytes(UnionBytes&&) = default;
6666
UnionBytes& operator=(UnionBytes&&) = default;
6767

68-
bool IsOneByte() const { return one_byte_resource_ != nullptr; }
68+
bool is_one_byte() const { return one_byte_resource_ != nullptr; }
6969

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

src/util.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ void SetConstructorFunction(Isolate* isolate,
552552
}
553553

554554
Local<String> UnionBytes::ToStringChecked(Isolate* isolate) const {
555-
if (IsOneByte()) {
555+
if (is_one_byte()) {
556556
return String::NewExternalOneByte(isolate, one_byte_resource_)
557557
.ToLocalChecked();
558558
} else {

test/cctest/test_per_process.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ namespace {
2121
TEST_F(PerProcessTest, EmbeddedSources) {
2222
const auto& sources = PerProcessTest::get_sources_for_test();
2323
ASSERT_TRUE(std::any_of(sources.cbegin(), sources.cend(), [](auto p) {
24-
return p.second.IsOneByte();
24+
return p.second.is_one_byte();
2525
})) << "BuiltinLoader::source_ should have some 8bit items";
2626

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

0 commit comments

Comments
 (0)