Skip to content

Commit e474525

Browse files
yfeldblumfacebook-github-bot
authored andcommitted
DynamicTimeseriesWrapper::add do strlen in caller
Reviewed By: Orvid Differential Revision: D74665184 fbshipit-source-id: 88f5eeba9a423bfb825d461c1dab973febfe7914
1 parent f02fa66 commit e474525

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

fb303/ThreadCachedServiceData.h

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,15 +1378,8 @@ class DynamicTimeseriesWrapper {
13781378
// E.g. add(1, "red", "cat");
13791379
// add(2, "red", 42);
13801380
template <typename... Args>
1381-
void add(int64_t value, Args&&... subkeys) {
1382-
auto key = key_.getFormattedKeyWithExtra(std::forward<Args>(subkeys)...);
1383-
if (key.second.get() == nullptr) {
1384-
ThreadCachedServiceData::ThreadLocalStatsMap& tcData =
1385-
*ThreadCachedServiceData::getStatsThreadLocal();
1386-
// Cache thread local counter
1387-
key.second.get() = tcData.getTimeseriesSafe(key.first);
1388-
}
1389-
key.second.get()->addValue(value);
1381+
FOLLY_ERASE void add(int64_t value, Args&&... subkeys) {
1382+
addImpl(value, cast(subkeys)...);
13901383
}
13911384

13921385
// "subkeys" must be a list of exactly N strings or integers, one for each
@@ -1445,6 +1438,25 @@ class DynamicTimeseriesWrapper {
14451438
}
14461439

14471440
private:
1441+
FOLLY_ERASE static int64_t cast(int64_t subkey) {
1442+
return subkey;
1443+
}
1444+
FOLLY_ERASE static std::string_view cast(std::string_view subkey) {
1445+
return subkey;
1446+
}
1447+
1448+
template <typename... Args>
1449+
void addImpl(int64_t value, Args... subkeys) {
1450+
auto key = key_.getFormattedKeyWithExtra(subkeys...);
1451+
if (key.second.get() == nullptr) {
1452+
ThreadCachedServiceData::ThreadLocalStatsMap& tcData =
1453+
*ThreadCachedServiceData::getStatsThreadLocal();
1454+
// Cache thread local counter
1455+
key.second.get() = tcData.getTimeseriesSafe(key.first);
1456+
}
1457+
key.second.get()->addValue(value);
1458+
}
1459+
14481460
inline ThreadCachedServiceData::ThreadLocalStatsMap& tcData() {
14491461
return *ThreadCachedServiceData::getStatsThreadLocal();
14501462
}

0 commit comments

Comments
 (0)