Skip to content

Commit

Permalink
zstd: Fix incorrect hash table placement for dict encoding in default (
Browse files Browse the repository at this point in the history
…#606)

Bonus: Load table values in same order they are used.
  • Loading branch information
klauspost authored May 30, 2022
1 parent c4c3195 commit dab79ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions zstd/enc_better.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ encodeLoop:
panic("offset0 was 0")
}

nextHashS := hashLen(cv, betterShortTableBits, betterShortLen)
nextHashL := hashLen(cv, betterLongTableBits, betterLongLen)
nextHashS := hashLen(cv, betterShortTableBits, betterShortLen)
candidateL := e.longTable[nextHashL]
candidateS := e.table[nextHashS]

Expand Down Expand Up @@ -518,8 +518,8 @@ encodeLoop:
}

// Store this, since we have it.
nextHashS := hashLen(cv, betterShortTableBits, betterShortLen)
nextHashL := hashLen(cv, betterLongTableBits, betterLongLen)
nextHashS := hashLen(cv, betterShortTableBits, betterShortLen)

// We have at least 4 byte match.
// No need to check backwards. We come straight from a match
Expand Down Expand Up @@ -674,8 +674,8 @@ encodeLoop:
panic("offset0 was 0")
}

nextHashS := hashLen(cv, betterShortTableBits, betterShortLen)
nextHashL := hashLen(cv, betterLongTableBits, betterLongLen)
nextHashS := hashLen(cv, betterShortTableBits, betterShortLen)
candidateL := e.longTable[nextHashL]
candidateS := e.table[nextHashS]

Expand Down Expand Up @@ -1047,8 +1047,8 @@ encodeLoop:
}

// Store this, since we have it.
nextHashS := hashLen(cv, betterShortTableBits, betterShortLen)
nextHashL := hashLen(cv, betterLongTableBits, betterLongLen)
nextHashS := hashLen(cv, betterShortTableBits, betterShortLen)

// We have at least 4 byte match.
// No need to check backwards. We come straight from a match
Expand Down
10 changes: 5 additions & 5 deletions zstd/enc_dfast.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ encodeLoop:
panic("offset0 was 0")
}

nextHashS := hashLen(cv, dFastShortTableBits, dFastShortLen)
nextHashL := hashLen(cv, dFastLongTableBits, dFastLongLen)
nextHashS := hashLen(cv, dFastShortTableBits, dFastShortLen)
candidateL := e.longTable[nextHashL]
candidateS := e.table[nextHashS]

Expand Down Expand Up @@ -439,8 +439,8 @@ encodeLoop:
var t int32
for {

nextHashS := hashLen(cv, dFastShortTableBits, dFastShortLen)
nextHashL := hashLen(cv, dFastLongTableBits, dFastLongLen)
nextHashS := hashLen(cv, dFastShortTableBits, dFastShortLen)
candidateL := e.longTable[nextHashL]
candidateS := e.table[nextHashS]

Expand Down Expand Up @@ -785,8 +785,8 @@ encodeLoop:
panic("offset0 was 0")
}

nextHashS := hashLen(cv, dFastShortTableBits, dFastShortLen)
nextHashL := hashLen(cv, dFastLongTableBits, dFastLongLen)
nextHashS := hashLen(cv, dFastShortTableBits, dFastShortLen)
candidateL := e.longTable[nextHashL]
candidateS := e.table[nextHashS]

Expand Down Expand Up @@ -969,7 +969,7 @@ encodeLoop:
te0 := tableEntry{offset: index0 + e.cur, val: uint32(cv0)}
te1 := tableEntry{offset: index1 + e.cur, val: uint32(cv1)}
longHash1 := hashLen(cv0, dFastLongTableBits, dFastLongLen)
longHash2 := hashLen(cv0, dFastLongTableBits, dFastLongLen)
longHash2 := hashLen(cv1, dFastLongTableBits, dFastLongLen)
e.longTable[longHash1] = te0
e.longTable[longHash2] = te1
e.markLongShardDirty(longHash1)
Expand Down Expand Up @@ -1002,8 +1002,8 @@ encodeLoop:
}

// Store this, since we have it.
nextHashS := hashLen(cv, dFastShortTableBits, dFastShortLen)
nextHashL := hashLen(cv, dFastLongTableBits, dFastLongLen)
nextHashS := hashLen(cv, dFastShortTableBits, dFastShortLen)

// We have at least 4 byte match.
// No need to check backwards. We come straight from a match
Expand Down

0 comments on commit dab79ca

Please sign in to comment.