@@ -59,11 +59,8 @@ type annotator[T any, M fileMetadata] struct {
59
59
// An AnnotationAggregator defines how an annotation should be accumulated from
60
60
// a single TableMetadata and merged with other annotated values.
61
61
type AnnotationAggregator [T any , M fileMetadata ] interface {
62
- // Zero returns the zero value of an annotation. This value is returned
63
- // when a LevelMetadata is empty. The dst argument, if non-nil, is an
64
- // obsolete value previously returned by this TableAnnotator and may be
65
- // overwritten and reused to avoid a memory allocation.
66
- Zero (dst * T ) * T
62
+ // Zero returns the zero value of an annotation.
63
+ Zero () * T
67
64
68
65
// Accumulate computes the annotation for a single file in a level's
69
66
// metadata. It merges the file's value into dst and returns a bool flag
@@ -127,7 +124,7 @@ func (a *annotator[T, M]) findAnnotation(n *node[M]) *annotation {
127
124
annotator : a ,
128
125
v : atomic.Value {},
129
126
})
130
- n .annot [len (n .annot )- 1 ].v .Store (a .Aggregator .Zero (nil ))
127
+ n .annot [len (n .annot )- 1 ].v .Store (a .Aggregator .Zero ())
131
128
return & n .annot [len (n .annot )- 1 ]
132
129
}
133
130
@@ -145,7 +142,7 @@ func (a *annotator[T, M]) nodeAnnotation(n *node[M]) (t *T, cacheOK bool) {
145
142
return annot .v .Load ().(* T ), true
146
143
}
147
144
148
- t = a .Aggregator .Zero (t )
145
+ t = a .Aggregator .Zero ()
149
146
valid := true
150
147
151
148
for i := int16 (0 ); i <= n .count ; i ++ {
@@ -264,7 +261,7 @@ func (a *TableAnnotator[T]) accumulateRangeAnnotation(
264
261
// duplicate computation.
265
262
func (a * TableAnnotator [T ]) LevelAnnotation (lm LevelMetadata ) * T {
266
263
if lm .Empty () {
267
- return a .Aggregator .Zero (nil )
264
+ return a .Aggregator .Zero ()
268
265
}
269
266
270
267
v , _ := a .nodeAnnotation (lm .tree .root )
@@ -276,7 +273,7 @@ func (a *TableAnnotator[T]) LevelAnnotation(lm LevelMetadata) *T {
276
273
// key for pre-calculated values, so the same TableAnnotator must be used to avoid
277
274
// duplicate computation.
278
275
func (a * TableAnnotator [T ]) MultiLevelAnnotation (lms []LevelMetadata ) * T {
279
- aggregated := a .Aggregator .Zero (nil )
276
+ aggregated := a .Aggregator .Zero ()
280
277
for l := 0 ; l < len (lms ); l ++ {
281
278
if ! lms [l ].Empty () {
282
279
v := a .LevelAnnotation (lms [l ])
@@ -295,11 +292,10 @@ func (a *TableAnnotator[T]) LevelRangeAnnotation(
295
292
cmp base.Compare , lm LevelMetadata , bounds base.UserKeyBounds ,
296
293
) * T {
297
294
if lm .Empty () {
298
- return a .Aggregator .Zero (nil )
295
+ return a .Aggregator .Zero ()
299
296
}
300
297
301
- var dst * T
302
- dst = a .Aggregator .Zero (dst )
298
+ dst := a .Aggregator .Zero ()
303
299
dst = a .accumulateRangeAnnotation (lm .tree .root , cmp , bounds , false , false , dst )
304
300
return dst
305
301
}
@@ -308,8 +304,7 @@ func (a *TableAnnotator[T]) LevelRangeAnnotation(
308
304
// for all files within the given Version which are within the range
309
305
// defined by bounds.
310
306
func (a * TableAnnotator [T ]) VersionRangeAnnotation (v * Version , bounds base.UserKeyBounds ) * T {
311
- var dst * T
312
- dst = a .Aggregator .Zero (dst )
307
+ dst := a .Aggregator .Zero ()
313
308
accumulateSlice := func (ls LevelSlice ) {
314
309
if ls .Empty () {
315
310
return
@@ -331,7 +326,7 @@ func (a *TableAnnotator[T]) VersionRangeAnnotation(v *Version, bounds base.UserK
331
326
// so the same TableAnnotator must be used to avoid duplicate computation.
332
327
func (a * BlobFileAnnotator [T ]) Annotation (blobFiles * BlobFileSet ) * T {
333
328
if blobFiles .tree .Count () == 0 {
334
- return a .Aggregator .Zero (nil )
329
+ return a .Aggregator .Zero ()
335
330
}
336
331
337
332
v , _ := a .nodeAnnotation (blobFiles .tree .root )
@@ -346,12 +341,8 @@ type SumAggregator struct {
346
341
}
347
342
348
343
// Zero implements AnnotationAggregator.Zero, returning a new uint64 set to 0.
349
- func (sa SumAggregator ) Zero (dst * uint64 ) * uint64 {
350
- if dst == nil {
351
- return new (uint64 )
352
- }
353
- * dst = 0
354
- return dst
344
+ func (sa SumAggregator ) Zero () * uint64 {
345
+ return new (uint64 )
355
346
}
356
347
357
348
// Accumulate implements AnnotationAggregator.Accumulate, accumulating a single
@@ -414,7 +405,7 @@ type PickFileAggregator struct {
414
405
}
415
406
416
407
// Zero implements AnnotationAggregator.Zero, returning nil as the zero value.
417
- func (fa PickFileAggregator ) Zero (dst * TableMetadata ) * TableMetadata {
408
+ func (fa PickFileAggregator ) Zero () * TableMetadata {
418
409
return nil
419
410
}
420
411
0 commit comments