Merge pull request #6379 from Adrian Cole

* gh-6379:
  Improves metrics performance by not guarding map.get
This commit is contained in:
Andy Wilkinson 2016-07-13 08:56:56 +01:00
commit 8319291efd
3 changed files with 12 additions and 9 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -58,8 +58,9 @@ public class BufferCounterService implements CounterService {
}
private String wrap(String metricName) {
if (this.names.containsKey(metricName)) {
return this.names.get(metricName);
String cached = this.names.get(metricName);
if (cached != null) {
return cached;
}
if (metricName.startsWith("counter") || metricName.startsWith("meter")) {
return metricName;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -128,8 +128,9 @@ public class DropwizardMetricServices implements CounterService, GaugeService {
}
private String wrapName(String metricName, String prefix) {
if (this.names.containsKey(metricName)) {
return this.names.get(metricName);
String cached = this.names.get(metricName);
if (cached != null) {
return cached;
}
if (metricName.startsWith(prefix)) {
return metricName;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -55,8 +55,9 @@ public class DefaultCounterService implements CounterService {
}
private String wrap(String metricName) {
if (this.names.containsKey(metricName)) {
return this.names.get(metricName);
String cached = this.names.get(metricName);
if (cached != null) {
return cached;
}
if (metricName.startsWith("counter.") || metricName.startsWith("meter.")) {
return metricName;