Skip to content

Commit 3a12933

Browse files
committed
manifest: remove AnnotationAggregator.Zero() argument
We always pass `nil` to this method.
1 parent 92cba40 commit 3a12933

File tree

2 files changed

+17
-34
lines changed

2 files changed

+17
-34
lines changed

internal/manifest/annotator.go

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,8 @@ type annotator[T any, M fileMetadata] struct {
5959
// An AnnotationAggregator defines how an annotation should be accumulated from
6060
// a single TableMetadata and merged with other annotated values.
6161
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
6764

6865
// Accumulate computes the annotation for a single file in a level's
6966
// 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 {
127124
annotator: a,
128125
v: atomic.Value{},
129126
})
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())
131128
return &n.annot[len(n.annot)-1]
132129
}
133130

@@ -145,7 +142,7 @@ func (a *annotator[T, M]) nodeAnnotation(n *node[M]) (t *T, cacheOK bool) {
145142
return annot.v.Load().(*T), true
146143
}
147144

148-
t = a.Aggregator.Zero(t)
145+
t = a.Aggregator.Zero()
149146
valid := true
150147

151148
for i := int16(0); i <= n.count; i++ {
@@ -264,7 +261,7 @@ func (a *TableAnnotator[T]) accumulateRangeAnnotation(
264261
// duplicate computation.
265262
func (a *TableAnnotator[T]) LevelAnnotation(lm LevelMetadata) *T {
266263
if lm.Empty() {
267-
return a.Aggregator.Zero(nil)
264+
return a.Aggregator.Zero()
268265
}
269266

270267
v, _ := a.nodeAnnotation(lm.tree.root)
@@ -276,7 +273,7 @@ func (a *TableAnnotator[T]) LevelAnnotation(lm LevelMetadata) *T {
276273
// key for pre-calculated values, so the same TableAnnotator must be used to avoid
277274
// duplicate computation.
278275
func (a *TableAnnotator[T]) MultiLevelAnnotation(lms []LevelMetadata) *T {
279-
aggregated := a.Aggregator.Zero(nil)
276+
aggregated := a.Aggregator.Zero()
280277
for l := 0; l < len(lms); l++ {
281278
if !lms[l].Empty() {
282279
v := a.LevelAnnotation(lms[l])
@@ -295,11 +292,10 @@ func (a *TableAnnotator[T]) LevelRangeAnnotation(
295292
cmp base.Compare, lm LevelMetadata, bounds base.UserKeyBounds,
296293
) *T {
297294
if lm.Empty() {
298-
return a.Aggregator.Zero(nil)
295+
return a.Aggregator.Zero()
299296
}
300297

301-
var dst *T
302-
dst = a.Aggregator.Zero(dst)
298+
dst := a.Aggregator.Zero()
303299
dst = a.accumulateRangeAnnotation(lm.tree.root, cmp, bounds, false, false, dst)
304300
return dst
305301
}
@@ -308,8 +304,7 @@ func (a *TableAnnotator[T]) LevelRangeAnnotation(
308304
// for all files within the given Version which are within the range
309305
// defined by bounds.
310306
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()
313308
accumulateSlice := func(ls LevelSlice) {
314309
if ls.Empty() {
315310
return
@@ -331,7 +326,7 @@ func (a *TableAnnotator[T]) VersionRangeAnnotation(v *Version, bounds base.UserK
331326
// so the same TableAnnotator must be used to avoid duplicate computation.
332327
func (a *BlobFileAnnotator[T]) Annotation(blobFiles *BlobFileSet) *T {
333328
if blobFiles.tree.Count() == 0 {
334-
return a.Aggregator.Zero(nil)
329+
return a.Aggregator.Zero()
335330
}
336331

337332
v, _ := a.nodeAnnotation(blobFiles.tree.root)
@@ -346,12 +341,8 @@ type SumAggregator struct {
346341
}
347342

348343
// 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)
355346
}
356347

357348
// Accumulate implements AnnotationAggregator.Accumulate, accumulating a single
@@ -414,7 +405,7 @@ type PickFileAggregator struct {
414405
}
415406

416407
// Zero implements AnnotationAggregator.Zero, returning nil as the zero value.
417-
func (fa PickFileAggregator) Zero(dst *TableMetadata) *TableMetadata {
408+
func (fa PickFileAggregator) Zero() *TableMetadata {
418409
return nil
419410
}
420411

table_stats.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,12 +1139,8 @@ var compressionStatsAnnotator = manifest.NewTableAnnotator[CompressionMetrics](c
11391139

11401140
type compressionStatsAggregator struct{}
11411141

1142-
func (a compressionStatsAggregator) Zero(dst *CompressionMetrics) *CompressionMetrics {
1143-
if dst == nil {
1144-
return new(CompressionMetrics)
1145-
}
1146-
*dst = CompressionMetrics{}
1147-
return dst
1142+
func (a compressionStatsAggregator) Zero() *CompressionMetrics {
1143+
return &CompressionMetrics{}
11481144
}
11491145

11501146
func (a compressionStatsAggregator) Accumulate(
@@ -1182,12 +1178,8 @@ var blobCompressionStatsAnnotator = manifest.NewBlobFileAnnotator[CompressionMet
11821178

11831179
type blobCompressionStatsAggregator struct{}
11841180

1185-
func (a blobCompressionStatsAggregator) Zero(dst *CompressionMetrics) *CompressionMetrics {
1186-
if dst == nil {
1187-
return new(CompressionMetrics)
1188-
}
1189-
*dst = CompressionMetrics{}
1190-
return dst
1181+
func (a blobCompressionStatsAggregator) Zero() *CompressionMetrics {
1182+
return &CompressionMetrics{}
11911183
}
11921184

11931185
func (a blobCompressionStatsAggregator) Accumulate(

0 commit comments

Comments
 (0)