Skip to content

Commit b470ba0

Browse files
authored
src: clean up generic counter implementation
This addresses late review comments for the recently landed cfbfc1b and aligns the new code with the pre-existing V8 fast call counters. Refs: nodejs/node#60434 (review) PR-URL: nodejs/node#60447 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 8808094 commit b470ba0

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/node_debug.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,16 @@ using v8::Number;
2424
using v8::Object;
2525
using v8::Value;
2626

27-
thread_local std::unordered_map<std::string, int> generic_usage_counters;
27+
thread_local std::unordered_map<FastStringKey, int, FastStringKey::Hash>
28+
generic_usage_counters;
2829
thread_local std::unordered_map<FastStringKey, int, FastStringKey::Hash>
2930
v8_fast_api_call_counts;
3031

31-
void CountGenericUsage(const char* counter_name) {
32-
if (generic_usage_counters.find(counter_name) == generic_usage_counters.end())
33-
generic_usage_counters[counter_name] = 0;
32+
void CountGenericUsage(FastStringKey counter_name) {
3433
generic_usage_counters[counter_name]++;
3534
}
3635

37-
int GetGenericUsageCount(const char* counter_name) {
36+
int GetGenericUsageCount(FastStringKey counter_name) {
3837
return generic_usage_counters[counter_name];
3938
}
4039

@@ -53,8 +52,8 @@ void GetGenericUsageCount(const FunctionCallbackInfo<Value>& args) {
5352
return;
5453
}
5554
Utf8Value utf8_key(env->isolate(), args[0]);
56-
args.GetReturnValue().Set(
57-
GetGenericUsageCount(utf8_key.ToStringView().data()));
55+
args.GetReturnValue().Set(GetGenericUsageCount(
56+
FastStringKey::AllowDynamic(utf8_key.ToStringView())));
5857
}
5958

6059
void GetV8FastApiCallCount(const FunctionCallbackInfo<Value>& args) {

src/node_debug.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ namespace debug {
1313
void TrackV8FastApiCall(FastStringKey key);
1414
int GetV8FastApiCallCount(FastStringKey key);
1515

16-
void CountGenericUsage(const char* counter_name);
17-
#define COUNT_GENERIC_USAGE(name) node::debug::CountGenericUsage(name)
16+
void CountGenericUsage(FastStringKey counter_name);
17+
#define COUNT_GENERIC_USAGE(name) \
18+
node::debug::CountGenericUsage(FastStringKey(name))
1819

1920
#define TRACK_V8_FAST_API_CALL(key) \
2021
node::debug::TrackV8FastApiCall(FastStringKey(key))

0 commit comments

Comments
 (0)