electron/shell/renderer/api/context_bridge/object_cache.h
Samuel Attard 09870d97b5
perf: optimize data structures in context_bridge::ObjectCache (#27639)
* Use std::forward_list instead of base::LinkedList for better perf,
more consistent memory management.  Better than std::list because we
don't need the double-linked-list behavior of std::list
* Use std::unordered_map instead of std::map for the v8 hash table
2021-02-08 12:30:25 -08:00

46 lines
1.3 KiB
C++

// Copyright (c) 2020 Slack Technologies, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_RENDERER_API_CONTEXT_BRIDGE_OBJECT_CACHE_H_
#define SHELL_RENDERER_API_CONTEXT_BRIDGE_OBJECT_CACHE_H_
#include <unordered_map>
#include <utility>
#include "base/containers/linked_list.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_frame_observer.h"
#include "shell/renderer/electron_render_frame_observer.h"
#include "third_party/blink/public/web/web_local_frame.h"
namespace electron {
namespace api {
namespace context_bridge {
using ObjectCachePair = std::pair<v8::Local<v8::Value>, v8::Local<v8::Value>>;
class ObjectCache final {
public:
ObjectCache();
~ObjectCache();
void CacheProxiedObject(v8::Local<v8::Value> from,
v8::Local<v8::Value> proxy_value);
v8::MaybeLocal<v8::Value> GetCachedProxiedObject(
v8::Local<v8::Value> from) const;
private:
// object_identity ==> [from_value, proxy_value]
std::unordered_map<int, std::forward_list<ObjectCachePair>> proxy_map_;
};
} // namespace context_bridge
} // namespace api
} // namespace electron
#endif // SHELL_RENDERER_API_CONTEXT_BRIDGE_OBJECT_CACHE_H_