@@ -223,12 +223,7 @@ void BuiltinLoader::AddExternalizedBuiltin(const char* id,
223
223
{
224
224
Mutex::ScopedLock lock (externalized_builtins_mutex);
225
225
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 ()) {
232
227
std::string source;
233
228
int r = ReadFileSync (&source, filename);
234
229
if (r != 0 ) {
@@ -247,14 +242,17 @@ void BuiltinLoader::AddExternalizedBuiltin(const char* id,
247
242
reinterpret_cast <char16_t *>(out->data ()));
248
243
out->resize (u16_length);
249
244
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 ;
257
251
}
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 ();
258
256
}
259
257
260
258
Add (id, UnionBytes (resource));
0 commit comments