Skip to content

Commit

Permalink
Enforce consistency: always use a pointer receiver to call MaxEncoded…
Browse files Browse the repository at this point in the history
…Len (that way the size of the underlying struct does not matter)
  • Loading branch information
flanglet committed Jan 29, 2024
1 parent 869c4d9 commit 11ad09d
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion v2/transform/AliasCodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,6 @@ func (this *AliasCodec) Inverse(src, dst []byte) (uint, uint, error) {
}

// MaxEncodedLen returns the max size required for the encoding output buffer
func (this AliasCodec) MaxEncodedLen(srcLen int) int {
func (this *AliasCodec) MaxEncodedLen(srcLen int) int {
return srcLen + 1024
}
2 changes: 1 addition & 1 deletion v2/transform/BWT.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,6 @@ func GetBWTChunks(size int) int {
}

// MaxEncodedLen returns the max size required for the encoding output buffer
func (this BWT) MaxEncodedLen(srcLen int) int {
func (this *BWT) MaxEncodedLen(srcLen int) int {
return srcLen
}
2 changes: 1 addition & 1 deletion v2/transform/BWTBlockCodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,6 @@ func (this *BWTBlockCodec) Inverse(src, dst []byte) (uint, uint, error) {
}

// MaxEncodedLen returns the max size required for the encoding output buffer
func (this BWTBlockCodec) MaxEncodedLen(srcLen int) int {
func (this *BWTBlockCodec) MaxEncodedLen(srcLen int) int {
return srcLen + _BWT_MAX_HEADER_SIZE
}
2 changes: 1 addition & 1 deletion v2/transform/BWTS.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,6 @@ func (this *BWTS) Inverse(src, dst []byte) (uint, uint, error) {
}

// MaxEncodedLen returns the max size required for the encoding output buffer
func (this BWTS) MaxEncodedLen(srcLen int) int {
func (this *BWTS) MaxEncodedLen(srcLen int) int {
return srcLen
}
2 changes: 1 addition & 1 deletion v2/transform/EXECodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ func (this *EXECodec) inverseARM(src, dst []byte) (uint, uint, error) {
}

// MaxEncodedLen returns the max size required for the encoding output buffer
func (this EXECodec) MaxEncodedLen(srcLen int) int {
func (this *EXECodec) MaxEncodedLen(srcLen int) int {
// Allocate some extra buffer for incompressible data.
if srcLen <= 256 {
return srcLen + 32
Expand Down
2 changes: 1 addition & 1 deletion v2/transform/NullTransform.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ func (this *NullTransform) Inverse(src, dst []byte) (uint, uint, error) {
}

// MaxEncodedLen returns the max size required for the encoding output buffer
func (this NullTransform) MaxEncodedLen(srcLen int) int {
func (this *NullTransform) MaxEncodedLen(srcLen int) int {
return srcLen
}
2 changes: 1 addition & 1 deletion v2/transform/RLT.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ func (this *RLT) Inverse(src, dst []byte) (uint, uint, error) {
}

// MaxEncodedLen returns the max size required for the encoding output buffer
func (this RLT) MaxEncodedLen(srcLen int) int {
func (this *RLT) MaxEncodedLen(srcLen int) int {
if srcLen <= 512 {
return srcLen + 32
}
Expand Down
4 changes: 2 additions & 2 deletions v2/transform/ROLZCodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ End:
}

// MaxEncodedLen returns the max size required for the encoding output buffer
func (this rolzCodec1) MaxEncodedLen(srcLen int) int {
func (this *rolzCodec1) MaxEncodedLen(srcLen int) int {
if srcLen <= 512 {
return srcLen + 64
}
Expand Down Expand Up @@ -1352,7 +1352,7 @@ func (this *rolzCodec2) Inverse(src, dst []byte) (uint, uint, error) {
}

// MaxEncodedLen returns the max size required for the encoding output buffer
func (this rolzCodec2) MaxEncodedLen(srcLen int) int {
func (this *rolzCodec2) MaxEncodedLen(srcLen int) int {
// Since we do not check the dst index for each byte (for speed purpose)
// allocate some extra buffer for incompressible data.
if srcLen <= 16384 {
Expand Down
2 changes: 1 addition & 1 deletion v2/transform/SBRT.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,6 @@ func (this *SBRT) Inverse(src, dst []byte) (uint, uint, error) {
}

// MaxEncodedLen returns the max size required for the encoding output buffer
func (this SBRT) MaxEncodedLen(srcLen int) int {
func (this *SBRT) MaxEncodedLen(srcLen int) int {
return srcLen + _BWT_MAX_HEADER_SIZE
}
2 changes: 1 addition & 1 deletion v2/transform/SRT.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,6 @@ func (this SRT) decodeHeader(src []byte, freqs []int32) int {
}

// MaxEncodedLen returns the max size required for the encoding output buffer
func (this SRT) MaxEncodedLen(srcLen int) int {
func (this *SRT) MaxEncodedLen(srcLen int) int {
return srcLen + _SRT_MAX_HEADER_SIZE
}
2 changes: 1 addition & 1 deletion v2/transform/Sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (this *ByteTransformSequence) Inverse(src, dst []byte) (uint, uint, error)
}

// MaxEncodedLen returns the max size required for the encoding output buffer
func (this ByteTransformSequence) MaxEncodedLen(srcLen int) int {
func (this *ByteTransformSequence) MaxEncodedLen(srcLen int) int {
requiredSize := srcLen

for _, t := range this.transforms {
Expand Down
4 changes: 2 additions & 2 deletions v2/transform/TextCodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ func (this *textCodec1) Inverse(src, dst []byte) (uint, uint, error) {
return uint(srcIdx), uint(dstIdx), err
}

func (this textCodec1) MaxEncodedLen(srcLen int) int {
func (this *textCodec1) MaxEncodedLen(srcLen int) int {
// Limit to 1 x srcLength and let the caller deal with
// a failure when the output is too small
return srcLen
Expand Down Expand Up @@ -1626,7 +1626,7 @@ func (this *textCodec2) Inverse(src, dst []byte) (uint, uint, error) {
return uint(srcIdx), uint(dstIdx), err
}

func (this textCodec2) MaxEncodedLen(srcLen int) int {
func (this *textCodec2) MaxEncodedLen(srcLen int) int {
// Limit to 1 x srcLength and let the caller deal with
// a failure when the output is too small
return srcLen
Expand Down
2 changes: 1 addition & 1 deletion v2/transform/UTFCodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (this *UTFCodec) Inverse(src, dst []byte) (uint, uint, error) {
}

// MaxEncodedLen returns the max size required for the encoding output buffer
func (this UTFCodec) MaxEncodedLen(srcLen int) int {
func (this *UTFCodec) MaxEncodedLen(srcLen int) int {
return srcLen + 8192
}

Expand Down
2 changes: 1 addition & 1 deletion v2/transform/ZRLT.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,6 @@ End:
}

// MaxEncodedLen returns the max size required for the encoding output buffer
func (this ZRLT) MaxEncodedLen(srcLen int) int {
func (this *ZRLT) MaxEncodedLen(srcLen int) int {
return srcLen
}

0 comments on commit 11ad09d

Please sign in to comment.