src: clean up generic counter implementation · nodejs/node@5941341

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