Skip to content

Commit 674a6e4

Browse files
committed
Improved Meter.Id#getTags() performance
Signed-off-by: etki <[email protected]>
1 parent 169f38a commit 674a6e4

File tree

1 file changed

+9
-3
lines changed
  • micrometer-core/src/main/java/io/micrometer/core/instrument

1 file changed

+9
-3
lines changed

micrometer-core/src/main/java/io/micrometer/core/instrument/Meter.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public Id withTags(Iterable<Tag> tags) {
244244
/**
245245
* Generate a new id replacing all tags with new ones.
246246
* @param tags The tags to add.
247-
* @return A new id with the only the provided tags. The source id remains
247+
* @return A new id with only the provided tags. The source id remains
248248
* unchanged.
249249
* @since 1.1.0
250250
*/
@@ -282,8 +282,14 @@ public String getName() {
282282
* @return A set of dimensions that allows you to break down the name.
283283
*/
284284
public List<Tag> getTags() {
285-
List<Tag> tags = new ArrayList<>();
286-
this.tags.forEach(tags::add);
285+
if (this.tags == Tags.empty()) {
286+
return Collections.emptyList();
287+
}
288+
289+
List<Tag> tags = new ArrayList<>(32);
290+
for (Tag tag : this.tags) {
291+
tags.add(tag);
292+
}
287293
return Collections.unmodifiableList(tags);
288294
}
289295

0 commit comments

Comments
 (0)