kill a string allocation hotspot

This commit is contained in:
zab
2012-11-23 07:52:03 +00:00
parent 0ec77f5514
commit 55c264916b

View File

@ -803,17 +803,19 @@ public class TunnelPool {
* we also use the conservative algorithm instead * we also use the conservative algorithm instead
* *
**/ **/
final String rateName = buildRateName();
// Compute the average time it takes us to build a single tunnel of this type. // Compute the average time it takes us to build a single tunnel of this type.
int avg = 0; int avg = 0;
RateStat rs = _context.statManager().getRate(buildRateName()); RateStat rs = _context.statManager().getRate(rateName);
if (rs == null) { if (rs == null) {
// Create the RateStat here rather than at the top because // Create the RateStat here rather than at the top because
// the user could change the length settings while running // the user could change the length settings while running
_context.statManager().createRequiredRateStat(buildRateName(), _context.statManager().createRequiredRateStat(rateName,
"Tunnel Build Frequency", "Tunnels", "Tunnel Build Frequency", "Tunnels",
new long[] { TUNNEL_LIFETIME }); new long[] { TUNNEL_LIFETIME });
rs = _context.statManager().getRate(buildRateName()); rs = _context.statManager().getRate(rateName);
} }
if (rs != null) { if (rs != null) {
Rate r = rs.getRate(TUNNEL_LIFETIME); Rate r = rs.getRate(TUNNEL_LIFETIME);
@ -890,7 +892,7 @@ public class TunnelPool {
+ " soon " + expireSoon + " later " + expireLater + " soon " + expireSoon + " later " + expireLater
+ " std " + wanted + " inProgress " + inProgress + " fallback " + fallback + " std " + wanted + " inProgress " + inProgress + " fallback " + fallback
+ " for " + toString()); + " for " + toString());
_context.statManager().addRateData(buildRateName(), rv + inProgress, 0); _context.statManager().addRateData(rateName, rv + inProgress, 0);
return rv; return rv;
} }
@ -943,7 +945,7 @@ public class TunnelPool {
int rv = countHowManyToBuild(allowZeroHop, expire30s, expire90s, expire150s, expire210s, expire270s, int rv = countHowManyToBuild(allowZeroHop, expire30s, expire90s, expire150s, expire210s, expire270s,
expireLater, wanted, inProgress, fallback); expireLater, wanted, inProgress, fallback);
_context.statManager().addRateData(buildRateName(), (rv > 0 || inProgress > 0) ? 1 : 0, 0); _context.statManager().addRateData(rateName, (rv > 0 || inProgress > 0) ? 1 : 0, 0);
return rv; return rv;
} }