Browse Source

Merge pull request #12259 from bboreham/labels-overwrite

labels: add ScratchBuilder.Overwrite for slice implementation
pull/11687/head
Bartlomiej Plotka 2 years ago committed by GitHub
parent
commit
136b48855a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      model/labels/labels.go
  2. 2
      model/labels/labels_string.go

6
model/labels/labels.go

@ -631,3 +631,9 @@ func (b *ScratchBuilder) Labels() Labels {
// Copy the slice, so the next use of ScratchBuilder doesn't overwrite.
return append([]Label{}, b.add...)
}
// Write the newly-built Labels out to ls.
// Callers must ensure that there are no other references to ls, or any strings fetched from it.
func (b *ScratchBuilder) Overwrite(ls *Labels) {
*ls = append((*ls)[:0], b.add...)
}

2
model/labels/labels_string.go

@ -811,7 +811,7 @@ func (b *ScratchBuilder) Labels() Labels {
}
// Write the newly-built Labels out to ls, reusing an internal buffer.
// Callers must ensure that there are no other references to ls.
// Callers must ensure that there are no other references to ls, or any strings fetched from it.
func (b *ScratchBuilder) Overwrite(ls *Labels) {
size := labelsSize(b.add)
if size <= cap(b.overwriteBuffer) {

Loading…
Cancel
Save