From 11ad09d2d50c962066c59d5bc206136d6f547d0a Mon Sep 17 00:00:00 2001 From: Frederic Langlet Date: Mon, 29 Jan 2024 11:45:45 -0800 Subject: [PATCH] Enforce consistency: always use a pointer receiver to call MaxEncodedLen (that way the size of the underlying struct does not matter) --- v2/transform/AliasCodec.go | 2 +- v2/transform/BWT.go | 2 +- v2/transform/BWTBlockCodec.go | 2 +- v2/transform/BWTS.go | 2 +- v2/transform/EXECodec.go | 2 +- v2/transform/NullTransform.go | 2 +- v2/transform/RLT.go | 2 +- v2/transform/ROLZCodec.go | 4 ++-- v2/transform/SBRT.go | 2 +- v2/transform/SRT.go | 2 +- v2/transform/Sequence.go | 2 +- v2/transform/TextCodec.go | 4 ++-- v2/transform/UTFCodec.go | 2 +- v2/transform/ZRLT.go | 2 +- 14 files changed, 16 insertions(+), 16 deletions(-) diff --git a/v2/transform/AliasCodec.go b/v2/transform/AliasCodec.go index c6eacfef..8f654579 100644 --- a/v2/transform/AliasCodec.go +++ b/v2/transform/AliasCodec.go @@ -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 } diff --git a/v2/transform/BWT.go b/v2/transform/BWT.go index 3d75ede1..9260ab6b 100644 --- a/v2/transform/BWT.go +++ b/v2/transform/BWT.go @@ -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 } diff --git a/v2/transform/BWTBlockCodec.go b/v2/transform/BWTBlockCodec.go index 0929f1a9..af5dde2b 100644 --- a/v2/transform/BWTBlockCodec.go +++ b/v2/transform/BWTBlockCodec.go @@ -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 } diff --git a/v2/transform/BWTS.go b/v2/transform/BWTS.go index a4933bc6..53230460 100644 --- a/v2/transform/BWTS.go +++ b/v2/transform/BWTS.go @@ -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 } diff --git a/v2/transform/EXECodec.go b/v2/transform/EXECodec.go index ed70b586..312a1108 100644 --- a/v2/transform/EXECodec.go +++ b/v2/transform/EXECodec.go @@ -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 diff --git a/v2/transform/NullTransform.go b/v2/transform/NullTransform.go index d678f783..a424774f 100644 --- a/v2/transform/NullTransform.go +++ b/v2/transform/NullTransform.go @@ -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 } diff --git a/v2/transform/RLT.go b/v2/transform/RLT.go index aeaa71e4..52f678ea 100644 --- a/v2/transform/RLT.go +++ b/v2/transform/RLT.go @@ -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 } diff --git a/v2/transform/ROLZCodec.go b/v2/transform/ROLZCodec.go index a12be6cb..9b09a412 100644 --- a/v2/transform/ROLZCodec.go +++ b/v2/transform/ROLZCodec.go @@ -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 } @@ -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 { diff --git a/v2/transform/SBRT.go b/v2/transform/SBRT.go index b96ea859..3f88ea22 100644 --- a/v2/transform/SBRT.go +++ b/v2/transform/SBRT.go @@ -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 } diff --git a/v2/transform/SRT.go b/v2/transform/SRT.go index 9f9713ce..1590df49 100644 --- a/v2/transform/SRT.go +++ b/v2/transform/SRT.go @@ -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 } diff --git a/v2/transform/Sequence.go b/v2/transform/Sequence.go index a94a842a..4b3f27be 100644 --- a/v2/transform/Sequence.go +++ b/v2/transform/Sequence.go @@ -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 { diff --git a/v2/transform/TextCodec.go b/v2/transform/TextCodec.go index 958c0309..a6e3c294 100644 --- a/v2/transform/TextCodec.go +++ b/v2/transform/TextCodec.go @@ -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 @@ -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 diff --git a/v2/transform/UTFCodec.go b/v2/transform/UTFCodec.go index 120d8b56..b4da8836 100644 --- a/v2/transform/UTFCodec.go +++ b/v2/transform/UTFCodec.go @@ -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 } diff --git a/v2/transform/ZRLT.go b/v2/transform/ZRLT.go index a9eae702..0ae2be84 100644 --- a/v2/transform/ZRLT.go +++ b/v2/transform/ZRLT.go @@ -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 }