Skip to content

Commit

Permalink
refactor(pool): package level builder pool is now private
Browse files Browse the repository at this point in the history
  • Loading branch information
wazazaby committed Sep 16, 2024
1 parent 1c1decb commit 556ec5c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ func (b *Builder) Reset() {
}

// Metric acquires and returns a zeroed-out [Builder] instance from the
// [DefaultBuilderPool] and sets the metric's name.
// default builder pool and sets the metric's name.
func Metric(name string, options ...BuilderOption) *Builder {
return DefaultBuilderPool.Metric(name, options...)
return defaultBuilderPool.Metric(name, options...)
}

// Metric sets the metric's name of the [Builder].
Expand Down
10 changes: 5 additions & 5 deletions builder_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const (
)

var (
DefaultBuilderPool = NewBuilderPool()
defaultBuilderPool = NewBuilderPool()
)

// NewBuilderPool creates a new [BuilderPool] instance.
Expand Down Expand Up @@ -38,12 +38,12 @@ func (p *BuilderPool) Acquire() *Builder {
return p.pool.Get().(*Builder)
}

// AcquireBuilder returns an empty [Builder] instance from the [DefaultBuilderPool].
// AcquireBuilder returns an empty [Builder] instance from the default builder pool.
//
// Release the [Builder] with [ReleaseBuilder] after the [Builder] is no longer needed.
// This allows reducing GC load.
func AcquireBuilder() *Builder {
return DefaultBuilderPool.Acquire()
return defaultBuilderPool.Acquire()
}

// Release releases the [Builder] acquired via [BuilderPool.Acquire] to the specified pool.
Expand All @@ -55,12 +55,12 @@ func (p *BuilderPool) Release(b *Builder) {
p.pool.Put(b)
}

// Release releases the [Builder] acquired via [AcquireBuilder] to the [DefaultBuilderPool].
// Release releases the [Builder] acquired via [AcquireBuilder] to the default builder pool.
//
// The released [Builder] mustn't be used after releasing it, otherwise data races
// may occur.
func ReleaseBuilder(b *Builder) {
DefaultBuilderPool.Release(b)
defaultBuilderPool.Release(b)
}

// Metric acquires and returns a zeroed-out [Builder] instance from the
Expand Down

0 comments on commit 556ec5c

Please sign in to comment.