Skip to content

Commit

Permalink
Fix passing literals
Browse files Browse the repository at this point in the history
  • Loading branch information
WojciechMula committed Mar 17, 2022
1 parent e7c2468 commit 9d30996
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
14 changes: 0 additions & 14 deletions zstd/decoder_test.go
Expand Up @@ -806,12 +806,6 @@ func TestDecoder_Reset(t *testing.T) {
t.Error(err, len(decoded))
}
if !bytes.Equal(decoded, in) {
// TODO XXX: don't forget to remove
for i := range in {
if in[i] != decoded[i] {
fmt.Printf("%d: %02x != %02x\n", i, in[i], decoded[i])
}
}
t.Fatal("Decoded does not match")
}
t.Log("Encoded content matched")
Expand Down Expand Up @@ -961,14 +955,6 @@ func TestDecoderMultiFrameReset(t *testing.T) {
}
got, err := ioutil.ReadAll(dec)
if err != nil {
// XXX: to remove
if false {
for i := range in {
if in[i] != got[i] {
fmt.Printf("%d: %02x != %02x\n", i, in[i], got[i])
}
}
}
t.Fatal(err)
}
err = dec.Reset(bytes.NewBuffer(in))
Expand Down
13 changes: 3 additions & 10 deletions zstd/seqdec_amd64.go
Expand Up @@ -120,34 +120,26 @@ func (s *sequenceDecs) executeSimple(seqs []seqVals) error {
seqs: seqs,
seqIndex: 0,
out: out,
literals: s.literals,
}

// XXX: to remove
//fmt.Printf("executeSimple\n")
for ctx.seqIndex < len(seqs) {
ctx.outPosition = t
ctx.litPosition = 0
ctx.literals = s.literals
completed := sequenceDecs_executeSimple_amd64(&ctx)
if completed {
// The asm routine did everything
s.literals = s.literals[ctx.litPosition:]
t = ctx.outPosition
// XXX: to remove
/*fmt.Printf("Fast path: index=%d, t=%d, len(out)=%d, len(s.literals)=%d\n",
ctx.seqIndex, t, len(out), len(s.literals))*/
break
}

// The asm routine cannot handle seq[ctx.index]
seq := seqs[ctx.seqIndex]
t = ctx.outPosition
s.literals = s.literals[ctx.litPosition:]
ctx.seqIndex += 1

// XXX: to remove
/*fmt.Printf("Slow path: index=%d, t=%d, seq=%+v, len(out)=%d, len(s.literals)=%d\n",
ctx.seqIndex, t, seq, len(out), len(s.literals))*/
ctx.seqIndex += 1

// Add literals
copy(out[t:], s.literals[:seq.ll])
Expand Down Expand Up @@ -180,6 +172,7 @@ func (s *sequenceDecs) executeSimple(seqs []seqVals) error {
}
}
}

// Add final literals
copy(out[t:], s.literals)
if debugDecoder {
Expand Down
2 changes: 2 additions & 0 deletions zstd/seqdec_generic.go
Expand Up @@ -170,6 +170,7 @@ func (s *sequenceDecs) executeSimple(seqs []seqVals) error {
out := s.out[:t+s.seqSize]

for _, seq := range seqs {

// Add literals
copy(out[t:], s.literals[:seq.ll])
t += seq.ll
Expand Down Expand Up @@ -201,6 +202,7 @@ func (s *sequenceDecs) executeSimple(seqs []seqVals) error {
}
}
}

// Add final literals
copy(out[t:], s.literals)
if debugDecoder {
Expand Down

0 comments on commit 9d30996

Please sign in to comment.