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:
Anna Henningsen
2025-07-21 18:18:44 +02:00
committed by Node.js GitHub Bot
parent dad44c928d
commit 6bb08f7f8e
2 changed files with 11 additions and 8 deletions

View File

@@ -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) {

View File

@@ -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