@@ -131,6 +131,10 @@ type BlockPropertyCollector interface {
131
131
// Finish appends the property value to buf and resets the collector to an
132
132
// empty state.
133
133
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 ()
134
138
}
135
139
136
140
// BlockPropertyFilter is used in an Iterator to filter sstables and blocks
@@ -250,11 +254,19 @@ func NewBlockIntervalCollector(
250
254
if mapper == nil {
251
255
panic ("mapper must be provided" )
252
256
}
253
- return & BlockIntervalCollector {
257
+ c := blockIntervalCollectorPool .Get ().(* BlockIntervalCollector )
258
+ * c = BlockIntervalCollector {
254
259
name : name ,
255
260
mapper : mapper ,
256
261
suffixReplacer : suffixReplacer ,
257
262
}
263
+ return c
264
+ }
265
+
266
+ var blockIntervalCollectorPool = sync.Pool {
267
+ New : func () interface {} {
268
+ return & BlockIntervalCollector {}
269
+ },
258
270
}
259
271
260
272
// Name is part of the BlockPropertyCollector interface.
@@ -328,6 +340,12 @@ func (b *BlockIntervalCollector) Finish(buf []byte) []byte {
328
340
return result
329
341
}
330
342
343
+ // Close is part of the BlockPropertyCollector interface.
344
+ func (b * BlockIntervalCollector ) Close () {
345
+ * b = BlockIntervalCollector {}
346
+ blockIntervalCollectorPool .Put (b )
347
+ }
348
+
331
349
// BlockInterval represents the [Lower, Upper) interval of 64-bit values
332
350
// corresponding to a set of keys. The meaning of the values themselves is
333
351
// opaque to the BlockIntervalCollector.
0 commit comments