From e974df7b50f2e5b4e559324cdd0d79f7f3f33da9 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Wed, 3 Jan 2024 09:06:07 -0800 Subject: [PATCH] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Robert PajÄ…k --- CHANGELOG.md | 2 +- attribute/set.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e08a209ab78..d33d430d270 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Improve `go.opentelemetry.io/otel/trace.TraceState`'s performance. (#4722) - Improve `go.opentelemetry.io/otel/propagation.TraceContext`'s performance. (#4721) - Improve `go.opentelemetry.io/otel/baggage` performance. (#4743) -- Imporove performance of the `(*Set).Filter` method in `go.opentelemetry.io/otel/attribute` when the passed filter does not filter out any attributes from the set. (#4774) +- Improve performance of the `(*Set).Filter` method in `go.opentelemetry.io/otel/attribute` when the passed filter does not filter out any attributes from the set. (#4774) - `Member.String` in `go.opentelemetry.io/otel/baggage` percent-encodes only when necessary. (#4775) ### Fixed diff --git a/attribute/set.go b/attribute/set.go index 8493bf818a5..7e6765b06b7 100644 --- a/attribute/set.go +++ b/attribute/set.go @@ -289,7 +289,7 @@ func NewSetWithSortableFiltered(kvs []KeyValue, tmp *Sortable, filter Filter) (S return Set{equivalent: computeDistinct(kvs)}, nil } -// filteredToFront filters slice in-place using f. All KeyValues that need to +// filteredToFront filters slice in-place using keep function. All KeyValues that need to // be removed are moved to the front. All KeyValues that need to be kept are // moved (in-order) to the back. The index for the first KeyValue to be kept is // returned. @@ -339,6 +339,7 @@ func (l *Set) Filter(re Filter) (Set, []KeyValue) { // attribute above that needs to be filtered out. return Set{equivalent: computeDistinct(slice[1:])}, slice[:1] } + // Move the filtered slice[first] to the front (preserving order). kv := slice[first] copy(slice[1:first+1], slice[:first])