Skip to content

Commit 95c4018

Browse files
committed
Avoid repeated toLowerCase in OtelInstrumentDescriptor.hashCode
1 parent e319fdd commit 95c4018

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

dd-java-agent/agent-otel/otel-bootstrap/src/main/java/datadog/trace/bootstrap/otel/metrics/OtelInstrumentDescriptor.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public final class OtelInstrumentDescriptor {
1212
private final boolean longValues;
1313
@Nullable private final UTF8BytesString description;
1414
@Nullable private final UTF8BytesString unit;
15+
private int hash;
1516

1617
public OtelInstrumentDescriptor(
1718
String instrumentName,
@@ -64,11 +65,15 @@ public boolean equals(Object o) {
6465

6566
@Override
6667
public int hashCode() {
67-
int result = instrumentName.toString().toLowerCase(Locale.ROOT).hashCode();
68-
result = 31 * result + instrumentType.hashCode();
69-
result = 31 * result + Boolean.hashCode(longValues);
70-
result = 31 * result + Objects.hashCode(description);
71-
result = 31 * result + Objects.hashCode(unit);
68+
int result = hash;
69+
if (result == 0) {
70+
result = instrumentName.toString().toLowerCase(Locale.ROOT).hashCode();
71+
result = 31 * result + instrumentType.hashCode();
72+
result = 31 * result + Boolean.hashCode(longValues);
73+
result = 31 * result + Objects.hashCode(description);
74+
result = 31 * result + Objects.hashCode(unit);
75+
hash = result;
76+
}
7277
return result;
7378
}
7479

0 commit comments

Comments
 (0)