diff --git a/src/main/java/com/threerings/util/MethodProfiler.java b/src/main/java/com/threerings/util/MethodProfiler.java index 3790dcbbe..2116c561f 100644 --- a/src/main/java/com/threerings/util/MethodProfiler.java +++ b/src/main/java/com/threerings/util/MethodProfiler.java @@ -23,8 +23,12 @@ package com.threerings.util; import java.util.Map; -import com.google.common.collect.MapMaker; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; import com.google.common.collect.Maps; +import com.google.common.primitives.Ints; + import com.samskivert.util.StringUtil; import static com.threerings.NaryaLog.log; @@ -122,8 +126,9 @@ public class MethodProfiler */ public Map getResults () { - Map results = Maps.newHashMapWithExpectedSize(_profiles.size()); - for (Map.Entry entry : _profiles.entrySet()) { + Map results = Maps.newHashMapWithExpectedSize( + Ints.saturatedCast(_profiles.size())); + for (Map.Entry entry : _profiles.asMap().entrySet()) { synchronized (entry.getValue()) { results.put(entry.getKey(), toResult(entry.getValue())); } @@ -196,7 +201,7 @@ public class MethodProfiler */ public void reset () { - _profiles.clear(); + _profiles.invalidateAll(); } /** @@ -204,7 +209,7 @@ public class MethodProfiler */ protected void recordTime (String method, double elapsedMs) { - RunningStats stats = _profiles.get(method); + RunningStats stats = _profiles.getUnchecked(method); synchronized (stats) { stats.addSample(elapsedMs); } @@ -331,6 +336,10 @@ public class MethodProfiler }; /** Stats by method name. */ - protected final Map _profiles = - new MapMaker().makeComputingMap(DefaultMap.newInstanceCreator(RunningStats.class)); + protected final Cache _profiles = CacheBuilder.newBuilder() + .build(new CacheLoader() { + public RunningStats load (String key) { + return new RunningStats(); + } + }); }