perf: use v8::Local<v8::Object> as the key in ObjectCache (#43568)
* perf: use v8::Object* as direct keys instead of using hash + a linked list Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: use v8::Local<v8::Object> as the key Co-authored-by: Charles Kerr <charles@charleskerr.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
parent
5d340577b6
commit
60247e685d
2 changed files with 25 additions and 34 deletions
|
@ -12,37 +12,22 @@ namespace electron::api::context_bridge {
|
|||
ObjectCache::ObjectCache() = default;
|
||||
ObjectCache::~ObjectCache() = default;
|
||||
|
||||
void ObjectCache::CacheProxiedObject(v8::Local<v8::Value> from,
|
||||
void ObjectCache::CacheProxiedObject(const v8::Local<v8::Value> from,
|
||||
v8::Local<v8::Value> proxy_value) {
|
||||
if (from->IsObject() && !from->IsNullOrUndefined()) {
|
||||
auto obj = from.As<v8::Object>();
|
||||
int hash = obj->GetIdentityHash();
|
||||
|
||||
proxy_map_[hash].emplace_front(from, proxy_value);
|
||||
}
|
||||
if (from->IsObject() && !from->IsNullOrUndefined())
|
||||
proxy_map_.insert_or_assign(from.As<v8::Object>(), proxy_value);
|
||||
}
|
||||
|
||||
v8::MaybeLocal<v8::Value> ObjectCache::GetCachedProxiedObject(
|
||||
v8::Local<v8::Value> from) const {
|
||||
const v8::Local<v8::Value> from) const {
|
||||
if (!from->IsObject() || from->IsNullOrUndefined())
|
||||
return v8::MaybeLocal<v8::Value>();
|
||||
return {};
|
||||
|
||||
auto obj = from.As<v8::Object>();
|
||||
int hash = obj->GetIdentityHash();
|
||||
auto iter = proxy_map_.find(hash);
|
||||
if (iter == proxy_map_.end())
|
||||
return v8::MaybeLocal<v8::Value>();
|
||||
const auto iter = proxy_map_.find(from.As<v8::Object>());
|
||||
if (iter == proxy_map_.end() || iter->second.IsEmpty())
|
||||
return {};
|
||||
|
||||
auto& list = iter->second;
|
||||
for (const auto& pair : list) {
|
||||
auto from_cmp = pair.first;
|
||||
if (from_cmp == from) {
|
||||
if (pair.second.IsEmpty())
|
||||
return v8::MaybeLocal<v8::Value>();
|
||||
return pair.second;
|
||||
}
|
||||
}
|
||||
return v8::MaybeLocal<v8::Value>();
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
} // namespace electron::api::context_bridge
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue