Skip to content

Commit b3fa190

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

File tree

1 file changed

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

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +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
248-
* unchanged.
247+
* @return A new id with only the provided tags. The source id remains unchanged.
249248
* @since 1.1.0
250249
*/
251250
public Id replaceTags(Iterable<Tag> tags) {
@@ -282,8 +281,14 @@ public String getName() {
282281
* @return A set of dimensions that allows you to break down the name.
283282
*/
284283
public List<Tag> getTags() {
285-
List<Tag> tags = new ArrayList<>();
286-
this.tags.forEach(tags::add);
284+
if (this.tags == Tags.empty()) {
285+
return Collections.emptyList();
286+
}
287+
288+
List<Tag> tags = new ArrayList<>(32);
289+
for (Tag tag : this.tags) {
290+
tags.add(tag);
291+
}
287292
return Collections.unmodifiableList(tags);
288293
}
289294

0 commit comments

Comments
 (0)