Skip to content

Commit

Permalink
Use cache for base time unit strings
Browse files Browse the repository at this point in the history
Closes gh-4352
  • Loading branch information
izeye committed Dec 11, 2023
1 parent 29e437b commit a28324b
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.*;
import java.util.stream.Collectors;

import static java.lang.String.format;
import static java.util.Collections.emptyList;
Expand Down Expand Up @@ -279,8 +280,13 @@ protected String getConventionName(Meter.Id id) {
*/
protected abstract DistributionStatisticConfig defaultHistogramConfig();

private static final EnumMap<TimeUnit, String> BASE_TIME_UNIT_STRING_CACHE = Arrays.stream(TimeUnit.values())
.collect(Collectors.toMap(Function.identity(), (timeUnit) -> timeUnit.toString().toLowerCase(), (l, r) -> {
throw new IllegalStateException("Duplicate keys should not exist.");
}, () -> new EnumMap<>(TimeUnit.class)));

private String getBaseTimeUnitStr() {
return getBaseTimeUnit().toString().toLowerCase();
return BASE_TIME_UNIT_STRING_CACHE.get(getBaseTimeUnit());
}

/**
Expand Down

0 comments on commit a28324b

Please sign in to comment.