Skip to content

Commit

Permalink
Flatten filterSet into only use
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Jan 2, 2024
1 parent 06cd155 commit c5ec192
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions attribute/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c5ec192

Please sign in to comment.