|
|
@@ -14,6 +14,11 @@ import (
|
|
|
// code.
|
|
|
const maxOffset = 1 << 15
|
|
|
|
|
|
+func load32(b []byte, i int32) uint32 {
|
|
|
+ b = b[i : i+4 : len(b)] // Help the compiler eliminate bounds checks on the next line.
|
|
|
+ return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
|
|
|
+}
|
|
|
+
|
|
|
// emitLiteral writes a literal chunk and returns the number of bytes written.
|
|
|
func emitLiteral(dst, lit []byte) int {
|
|
|
i, n := 0, uint(len(lit)-1)
|
|
|
@@ -165,8 +170,7 @@ func encodeBlock(dst, src []byte) (d int) {
|
|
|
)
|
|
|
for uint32(s+3) < uint32(len(src)) { // The uint32 conversions catch overflow from the +3.
|
|
|
// Update the hash table.
|
|
|
- b0, b1, b2, b3 := src[s], src[s+1], src[s+2], src[s+3]
|
|
|
- h := uint32(b0) | uint32(b1)<<8 | uint32(b2)<<16 | uint32(b3)<<24
|
|
|
+ h := load32(src, s)
|
|
|
p := &table[(h*0x1e35a7bd)>>shift]
|
|
|
// We need to to store values in [-1, inf) in table. To save
|
|
|
// some initialization time, (re)use the table's zero value
|
|
|
@@ -174,7 +178,7 @@ func encodeBlock(dst, src []byte) (d int) {
|
|
|
// subtract 1 on reads.
|
|
|
t, *p = *p-1, s+1
|
|
|
// If t is invalid or src[s:s+4] differs from src[t:t+4], accumulate a literal byte.
|
|
|
- if t < 0 || s-t >= maxOffset || b0 != src[t] || b1 != src[t+1] || b2 != src[t+2] || b3 != src[t+3] {
|
|
|
+ if t < 0 || s-t >= maxOffset || h != load32(src, t) {
|
|
|
s += int32(skip >> 5)
|
|
|
skip++
|
|
|
continue
|