Skip to content

Commit 77649ad

Browse files
addaleaxaduh95
authored andcommitted
src: use FastStringKey for TrackV8FastApiCall
This is the exact intended use case of `FastStringKey`. PR-URL: #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>
1 parent 86babf9 commit 77649ad

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/node_debug.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ using v8::Number;
2323
using v8::Object;
2424
using v8::Value;
2525

26-
thread_local std::unordered_map<std::string_view, int> v8_fast_api_call_counts;
26+
thread_local std::unordered_map<FastStringKey, int, FastStringKey::Hash>
27+
v8_fast_api_call_counts;
2728

28-
void TrackV8FastApiCall(std::string_view key) {
29+
void TrackV8FastApiCall(FastStringKey key) {
2930
v8_fast_api_call_counts[key]++;
3031
}
3132

32-
int GetV8FastApiCallCount(std::string_view key) {
33+
int GetV8FastApiCallCount(FastStringKey key) {
3334
return v8_fast_api_call_counts[key];
3435
}
3536

@@ -40,7 +41,8 @@ void GetV8FastApiCallCount(const FunctionCallbackInfo<Value>& args) {
4041
return;
4142
}
4243
Utf8Value utf8_key(env->isolate(), args[0]);
43-
args.GetReturnValue().Set(GetV8FastApiCallCount(utf8_key.ToStringView()));
44+
args.GetReturnValue().Set(GetV8FastApiCallCount(
45+
FastStringKey::AllowDynamic(utf8_key.ToStringView())));
4446
}
4547

4648
void SlowIsEven(const FunctionCallbackInfo<Value>& args) {

src/node_debug.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
44

55
#ifdef DEBUG
6-
#include <string_view>
6+
#include "util.h"
77
#endif // DEBUG
88

99
namespace node {
1010
namespace debug {
1111

1212
#ifdef DEBUG
13-
void TrackV8FastApiCall(std::string_view key);
14-
int GetV8FastApiCallCount(std::string_view key);
13+
void TrackV8FastApiCall(FastStringKey key);
14+
int GetV8FastApiCallCount(FastStringKey key);
1515

16-
#define TRACK_V8_FAST_API_CALL(key) node::debug::TrackV8FastApiCall(key)
16+
#define TRACK_V8_FAST_API_CALL(key) \
17+
node::debug::TrackV8FastApiCall(FastStringKey(key))
1718
#else // !DEBUG
1819
#define TRACK_V8_FAST_API_CALL(key)
1920
#endif // DEBUG

0 commit comments

Comments
 (0)