mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
Locally the hashing of the binding names sometimes has significant presence in the profile of bindings, because there can be collisions, which makes the cost of adding a new binding data non-trivial, but it's wasteful to spend time on hashing them or dealing with collisions at all, since we can just use the EmbedderObjectType enum as the key, as the string names are not actually used beyond debugging purposes and can be easily matched with a macro. And since we can just use the enum as the key, we do not even need the map and can just use an array with the enum as indices for the lookup. PR-URL: https://github.com/nodejs/node/pull/46620 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
54 lines
1.5 KiB
C++
54 lines
1.5 KiB
C++
|
|
#ifndef SRC_NODE_UTIL_H_
|
|
#define SRC_NODE_UTIL_H_
|
|
|
|
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
#include "base_object.h"
|
|
#include "node_snapshotable.h"
|
|
#include "v8.h"
|
|
|
|
namespace node {
|
|
namespace util {
|
|
|
|
class WeakReference : public SnapshotableObject {
|
|
public:
|
|
SERIALIZABLE_OBJECT_METHODS()
|
|
|
|
SET_OBJECT_ID(util_weak_reference)
|
|
|
|
WeakReference(Realm* realm,
|
|
v8::Local<v8::Object> object,
|
|
v8::Local<v8::Object> target);
|
|
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
static void Get(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
static void GetRef(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
static void IncRef(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
static void DecRef(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
SET_MEMORY_INFO_NAME(WeakReference)
|
|
SET_SELF_SIZE(WeakReference)
|
|
SET_NO_MEMORY_INFO()
|
|
|
|
struct InternalFieldInfo : public node::InternalFieldInfoBase {
|
|
SnapshotIndex target;
|
|
uint64_t reference_count;
|
|
};
|
|
|
|
private:
|
|
WeakReference(Realm* realm,
|
|
v8::Local<v8::Object> object,
|
|
v8::Local<v8::Object> target,
|
|
uint64_t reference_count);
|
|
v8::Global<v8::Object> target_;
|
|
uint64_t reference_count_ = 0;
|
|
|
|
SnapshotIndex target_index_ = 0; // 0 means target_ is not snapshotted
|
|
};
|
|
|
|
} // namespace util
|
|
} // namespace node
|
|
|
|
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
|
|
#endif // SRC_NODE_UTIL_H_
|