Merge pull request #12174 from bboreham/builder-range-smaller

labels: shrink stack arrays in Builder.Range
This commit is contained in:
Bryan Boreham 2023-03-23 11:40:29 +00:00 committed by GitHub
commit edc8e75c40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -547,8 +547,8 @@ func (b *Builder) Get(n string) string {
// Range calls f on each label in the Builder.
func (b *Builder) Range(f func(l Label)) {
// Stack-based arrays to avoid heap allocation in most cases.
var addStack [1024]Label
var delStack [1024]string
var addStack [128]Label
var delStack [128]string
// Take a copy of add and del, so they are unaffected by calls to Set() or Del().
origAdd, origDel := append(addStack[:0], b.add...), append(delStack[:0], b.del...)
b.base.Range(func(l Label) {

View File

@ -601,8 +601,8 @@ func (b *Builder) Get(n string) string {
// Range calls f on each label in the Builder.
func (b *Builder) Range(f func(l Label)) {
// Stack-based arrays to avoid heap allocation in most cases.
var addStack [1024]Label
var delStack [1024]string
var addStack [128]Label
var delStack [128]string
// Take a copy of add and del, so they are unaffected by calls to Set() or Del().
origAdd, origDel := append(addStack[:0], b.add...), append(delStack[:0], b.del...)
b.base.Range(func(l Label) {