mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
src: use FastStringKey for TrackV8FastApiCall
This is the exact intended use case of `FastStringKey`. PR-URL: https://github.com/nodejs/node/pull/59148 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Ilyas Shabi <ilyasshabi94@gmail.com>
This commit is contained in:
committed by
Node.js GitHub Bot
parent
dad44c928d
commit
6bb08f7f8e
@@ -23,13 +23,14 @@ using v8::Number;
|
||||
using v8::Object;
|
||||
using v8::Value;
|
||||
|
||||
thread_local std::unordered_map<std::string_view, int> v8_fast_api_call_counts;
|
||||
thread_local std::unordered_map<FastStringKey, int, FastStringKey::Hash>
|
||||
v8_fast_api_call_counts;
|
||||
|
||||
void TrackV8FastApiCall(std::string_view key) {
|
||||
void TrackV8FastApiCall(FastStringKey key) {
|
||||
v8_fast_api_call_counts[key]++;
|
||||
}
|
||||
|
||||
int GetV8FastApiCallCount(std::string_view key) {
|
||||
int GetV8FastApiCallCount(FastStringKey key) {
|
||||
return v8_fast_api_call_counts[key];
|
||||
}
|
||||
|
||||
@@ -40,7 +41,8 @@ void GetV8FastApiCallCount(const FunctionCallbackInfo<Value>& args) {
|
||||
return;
|
||||
}
|
||||
Utf8Value utf8_key(env->isolate(), args[0]);
|
||||
args.GetReturnValue().Set(GetV8FastApiCallCount(utf8_key.ToStringView()));
|
||||
args.GetReturnValue().Set(GetV8FastApiCallCount(
|
||||
FastStringKey::AllowDynamic(utf8_key.ToStringView())));
|
||||
}
|
||||
|
||||
void SlowIsEven(const FunctionCallbackInfo<Value>& args) {
|
||||
|
||||
@@ -3,17 +3,18 @@
|
||||
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <string_view>
|
||||
#include "util.h"
|
||||
#endif // DEBUG
|
||||
|
||||
namespace node {
|
||||
namespace debug {
|
||||
|
||||
#ifdef DEBUG
|
||||
void TrackV8FastApiCall(std::string_view key);
|
||||
int GetV8FastApiCallCount(std::string_view key);
|
||||
void TrackV8FastApiCall(FastStringKey key);
|
||||
int GetV8FastApiCallCount(FastStringKey key);
|
||||
|
||||
#define TRACK_V8_FAST_API_CALL(key) node::debug::TrackV8FastApiCall(key)
|
||||
#define TRACK_V8_FAST_API_CALL(key) \
|
||||
node::debug::TrackV8FastApiCall(FastStringKey(key))
|
||||
#else // !DEBUG
|
||||
#define TRACK_V8_FAST_API_CALL(key)
|
||||
#endif // DEBUG
|
||||
|
||||
Reference in New Issue
Block a user