Browse Source

lz4: removed init function and unused consts

Pierre Curto 6 years ago
parent
commit
dbab9a2a02
2 changed files with 12 additions and 18 deletions
  1. 0 4
      block.go
  2. 12 14
      lz4.go

+ 0 - 4
block.go

@@ -64,10 +64,8 @@ func CompressBlock(src, dst []byte, hashTable []int) (di int, err error) {
 	var si int
 
 	// Fast scan strategy: the hash table only stores the last 4 bytes sequences.
-	// const accInit = 1 << skipStrength
 
 	anchor := si // Position of the current literals.
-	// acc := accInit // Variable step: improves performance on non-compressible data.
 
 	for si < sn {
 		// Hash the next 4 bytes (sequence)...
@@ -83,8 +81,6 @@ func CompressBlock(src, dst []byte, hashTable []int) (di int, err error) {
 		offset := si - ref
 		if offset <= 0 || offset >= winSize || // Out of window.
 			match != binary.LittleEndian.Uint32(src[ref:]) { // Hash collision on different matches.
-			// si += acc >> skipStrength
-			// acc++
 			si++
 			continue
 		}

+ 12 - 14
lz4.go

@@ -31,26 +31,24 @@ const (
 	// Its value influences the compression speed and memory usage, the lower the faster,
 	// but at the expense of the compression ratio.
 	// 16 seems to be the best compromise.
-	hashLog       = 16
-	hashTableSize = 1 << hashLog
-	hashShift     = uint((minMatch * 8) - hashLog)
+	hashLog   = 16
+	hashShift = uint((minMatch * 8) - hashLog)
 
-	mfLimit      = 8 + minMatch // The last match cannot start within the last 12 bytes.
-	skipStrength = 6            // variable step for fast scan
+	mfLimit = 8 + minMatch // The last match cannot start within the last 12 bytes.
 )
 
 // map the block max size id with its value in bytes: 64Kb, 256Kb, 1Mb and 4Mb.
-var (
-	bsMapID    = map[byte]int{4: 64 << 10, 5: 256 << 10, 6: 1 << 20, 7: 4 << 20}
-	bsMapValue = make(map[int]byte, len(bsMapID))
+const (
+	blockSize64K  = 64 << 10
+	blockSize256K = 256 << 10
+	blockSize1M   = 1 << 20
+	blockSize4M   = 4 << 20
 )
 
-// Reversed.
-func init() {
-	for i, v := range bsMapID {
-		bsMapValue[v] = i
-	}
-}
+var (
+	bsMapID    = map[byte]int{4: blockSize64K, 5: blockSize256K, 6: blockSize1M, 7: blockSize4M}
+	bsMapValue = map[int]byte{blockSize64K: 4, blockSize256K: 5, blockSize1M: 6, blockSize4M: 7}
+)
 
 // Header describes the various flags that can be set on a Writer or obtained from a Reader.
 // The default values match those of the LZ4 frame format definition