Skip to content

Commit

Permalink
Added some explanation to the deltaCapacity function
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-sili committed Feb 5, 2025
1 parent 4f8b1fb commit a3b9539
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions exporter/exporterhelper/logs_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ func extractScopeLogsBasedOnByteSize(srcSL plog.ScopeLogs, capacity int) (plog.S
}

// deltaCapacity() returns the delta size of a proto slice when a new item is added.
// Example:
//
// prevSize := proto1.Size()
// proto1.RepeatedField().AppendEmpty() = proto2
//
// Then currSize of proto1 can be calculated as
//
// currSize := (prevSize + deltaCapacity(proto2.Size()))
//
// This is derived from gogo/protobuf 's Size() function
func deltaCapacity(newItemSize int) int {
return 1 + newItemSize + int(math_bits.Len64(uint64(newItemSize|1)+6)/7)
}

0 comments on commit a3b9539

Please sign in to comment.