diff --git a/shell/renderer/api/context_bridge/object_cache.cc b/shell/renderer/api/context_bridge/object_cache.cc index 9646d5358a19a..72ab60d24e99e 100644 --- a/shell/renderer/api/context_bridge/object_cache.cc +++ b/shell/renderer/api/context_bridge/object_cache.cc @@ -14,22 +14,8 @@ namespace api { namespace context_bridge { -ObjectCachePairNode::ObjectCachePairNode(ObjectCachePair&& pair) { - this->pair = std::move(pair); -} - -ObjectCachePairNode::~ObjectCachePairNode() = default; - ObjectCache::ObjectCache() {} -ObjectCache::~ObjectCache() { - for (const auto& pair : proxy_map_) { - while (!pair.second.empty()) { - ObjectCachePairNode* node = pair.second.head()->value(); - node->RemoveFromList(); - delete node; - } - } -} +ObjectCache::~ObjectCache() = default; void ObjectCache::CacheProxiedObject(v8::Local from, v8::Local proxy_value) { @@ -37,8 +23,7 @@ void ObjectCache::CacheProxiedObject(v8::Local from, auto obj = v8::Local::Cast(from); int hash = obj->GetIdentityHash(); - auto* node = new ObjectCachePairNode(std::make_pair(from, proxy_value)); - proxy_map_[hash].Append(node); + proxy_map_[hash].push_front(std::make_pair(from, proxy_value)); } } @@ -54,8 +39,7 @@ v8::MaybeLocal ObjectCache::GetCachedProxiedObject( return v8::MaybeLocal(); auto& list = iter->second; - for (auto* node = list.head(); node != list.end(); node = node->next()) { - auto& pair = node->value()->pair; + for (const auto& pair : list) { auto from_cmp = pair.first; if (from_cmp == from) { if (pair.second.IsEmpty()) diff --git a/shell/renderer/api/context_bridge/object_cache.h b/shell/renderer/api/context_bridge/object_cache.h index ff420f7368439..e40cd89d5b2a5 100644 --- a/shell/renderer/api/context_bridge/object_cache.h +++ b/shell/renderer/api/context_bridge/object_cache.h @@ -5,7 +5,7 @@ #ifndef SHELL_RENDERER_API_CONTEXT_BRIDGE_OBJECT_CACHE_H_ #define SHELL_RENDERER_API_CONTEXT_BRIDGE_OBJECT_CACHE_H_ -#include +#include #include #include "base/containers/linked_list.h" @@ -22,13 +22,6 @@ namespace context_bridge { using ObjectCachePair = std::pair, v8::Local>; -struct ObjectCachePairNode : public base::LinkNode { - explicit ObjectCachePairNode(ObjectCachePair&& pair); - ~ObjectCachePairNode(); - - ObjectCachePair pair; -}; - class ObjectCache final { public: ObjectCache(); @@ -41,7 +34,7 @@ class ObjectCache final { private: // object_identity ==> [from_value, proxy_value] - std::map> proxy_map_; + std::unordered_map> proxy_map_; }; } // namespace context_bridge