Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2020-04-19 22:51:05 +0300
committerAnna Henningsen <anna@addaleax.net>2020-05-06 07:44:04 +0300
commit86fdaa745572a3bec4370ac7bd05d18e6bf64c01 (patch)
tree45890dbc713ad29edd830fd2aa17f592909ccbb7 /src/util.h
parentf446b2058dcfaf9d4e2f6bdfe555bc4437f41acf (diff)
src: retrieve binding data from the context
Instead of passing them through the data bound to function templates, store references to them in a list embedded inside the context. This makes the function templates more context-independent, and makes it possible to embed binding data in non-main contexts. Co-authored-by: Anna Henningsen <anna@addaleax.net> PR-URL: https://github.com/nodejs/node/pull/33139 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h
index 5eaa20b7601..979091e6d6e 100644
--- a/src/util.h
+++ b/src/util.h
@@ -764,6 +764,27 @@ class PersistentToLocal {
}
};
+// Can be used as a key for std::unordered_map when lookup performance is more
+// important than size and the keys are statically used to avoid redundant hash
+// computations.
+class FastStringKey {
+ public:
+ constexpr explicit FastStringKey(const char* name);
+
+ struct Hash {
+ constexpr size_t operator()(const FastStringKey& key) const;
+ };
+ constexpr bool operator==(const FastStringKey& other) const;
+
+ constexpr const char* c_str() const;
+
+ private:
+ static constexpr size_t HashImpl(const char* str);
+
+ const char* name_;
+ size_t cached_hash_;
+};
+
} // namespace node
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS