@@ -131,6 +131,10 @@ type BlockPropertyCollector interface {
131131 // Finish appends the property value to buf and resets the collector to an
132132 // empty state.
133133 Finish (buf []byte ) []byte
134+
135+ // Close can be used to allow the implementation to be reused in the future.
136+ // Once Close is called, the object must no longer be used.
137+ Close ()
134138}
135139
136140// BlockPropertyFilter is used in an Iterator to filter sstables and blocks
@@ -250,11 +254,19 @@ func NewBlockIntervalCollector(
250254 if mapper == nil {
251255 panic ("mapper must be provided" )
252256 }
253- return & BlockIntervalCollector {
257+ c := blockIntervalCollectorPool .Get ().(* BlockIntervalCollector )
258+ * c = BlockIntervalCollector {
254259 name : name ,
255260 mapper : mapper ,
256261 suffixReplacer : suffixReplacer ,
257262 }
263+ return c
264+ }
265+
266+ var blockIntervalCollectorPool = sync.Pool {
267+ New : func () interface {} {
268+ return & BlockIntervalCollector {}
269+ },
258270}
259271
260272// Name is part of the BlockPropertyCollector interface.
@@ -328,6 +340,12 @@ func (b *BlockIntervalCollector) Finish(buf []byte) []byte {
328340 return result
329341}
330342
343+ // Close is part of the BlockPropertyCollector interface.
344+ func (b * BlockIntervalCollector ) Close () {
345+ * b = BlockIntervalCollector {}
346+ blockIntervalCollectorPool .Put (b )
347+ }
348+
331349// BlockInterval represents the [Lower, Upper) interval of 64-bit values
332350// corresponding to a set of keys. The meaning of the values themselves is
333351// opaque to the BlockIntervalCollector.
0 commit comments