Avoid creating new slices for labels values on postings for matchers (#13958)

* Avoid creating new slices for labels values on postings for matchers

Signed-off-by: alanprot <alanprot@gmail.com>

* refactor

Signed-off-by: alanprot <alanprot@gmail.com>

---------

Signed-off-by: alanprot <alanprot@gmail.com>
This commit is contained in:
Alan Protasio 2024-04-24 07:41:33 -07:00 committed by GitHub
parent bd1878700b
commit d15869af32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 2 deletions

View File

@ -331,7 +331,7 @@ func postingsForMatcher(ctx context.Context, ix IndexReader, m *labels.Matcher)
return nil, err
}
var res []string
res := vals[:0]
for _, val := range vals {
if m.Matches(val) {
res = append(res, val)
@ -368,7 +368,7 @@ func inversePostingsForMatcher(ctx context.Context, ix IndexReader, m *labels.Ma
return nil, err
}
var res []string
res := vals[:0]
// If the inverse match is ="", we just want all the values.
if m.Type == labels.MatchEqual && m.Value == "" {
res = vals