From c5ec1920459f4dd4ac24fa5abff2edff950812b9 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Tue, 2 Jan 2024 14:07:53 -0800 Subject: [PATCH] Flatten filterSet into only use --- attribute/set.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/attribute/set.go b/attribute/set.go index f9bbdea0590c..3c8d9cf00a09 100644 --- a/attribute/set.go +++ b/attribute/set.go @@ -278,21 +278,13 @@ func NewSetWithSortableFiltered(kvs []KeyValue, tmp *Sortable, filter Filter) (S // TODO (MrAlias): there is a potential optimization here where the // filtering and uniquing are all done in the same step. For example: // https://github.com/open-telemetry/opentelemetry-go/blob/228cc878a0f5de19290e8b2035dc4d0019f2a249/attribute/set.go#L266-L300 - return filterSet(kvs, filter) + if div := filteredToFront(kvs, filter); div != 0 { + return Set{equivalent: computeDistinct(kvs[div:])}, kvs[:div] + } } return Set{equivalent: computeDistinct(kvs)}, nil } -// filterSet reorders kvs so that included keys are contiguous at the end of -// the slice, while excluded keys precede the included keys. -func filterSet(kvs []KeyValue, filter Filter) (Set, []KeyValue) { - k := filteredToFront(kvs, filter) - if k == 0 { - return Set{equivalent: computeDistinct(kvs)}, nil - } - return Set{equivalent: computeDistinct(kvs[k:])}, kvs[:k] -} - // filteredToFront filters slice in-place using f. 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