diff --git a/flate/deflate.go b/flate/deflate.go index 96c5b8bec6..86f4fd0371 100644 --- a/flate/deflate.go +++ b/flate/deflate.go @@ -132,8 +132,7 @@ func (d *compressor) fillDeflate(b []byte) int { s := d.state if s.index >= 2*windowSize-(minMatchLength+maxMatchLength) { // shift the window by windowSize - //copy(d.window[:], d.window[windowSize:2*windowSize]) - *(*[windowSize]byte)(d.window) = *(*[windowSize]byte)(d.window[windowSize:]) + copy(d.window[:], d.window[windowSize:2*windowSize]) s.index -= windowSize d.windowEnd -= windowSize if d.blockStart >= windowSize { diff --git a/flate/fast_encoder.go b/flate/fast_encoder.go index 152229afd5..95d3ef996e 100644 --- a/flate/fast_encoder.go +++ b/flate/fast_encoder.go @@ -90,8 +90,7 @@ func (e *fastGen) addBlock(src []byte) int32 { } // Move down offset := int32(len(e.hist)) - maxMatchOffset - // copy(e.hist[0:maxMatchOffset], e.hist[offset:]) - *(*[maxMatchOffset]byte)(e.hist) = *(*[maxMatchOffset]byte)(e.hist[offset:]) + copy(e.hist[0:maxMatchOffset], e.hist[offset:]) e.cur += offset e.hist = e.hist[:maxMatchOffset] } diff --git a/flate/huffman_bit_writer.go b/flate/huffman_bit_writer.go index 34b091af09..2bccd8e8eb 100644 --- a/flate/huffman_bit_writer.go +++ b/flate/huffman_bit_writer.go @@ -791,11 +791,9 @@ func (w *huffmanBitWriter) fillTokens() { // and offsetEncoding. // The number of literal and offset tokens is returned. func (w *huffmanBitWriter) indexTokens(t *tokens, filled bool) (numLiterals, numOffsets int) { - //copy(w.literalFreq[:], t.litHist[:]) - *(*[256]uint16)(w.literalFreq[:]) = t.litHist - //copy(w.literalFreq[256:], t.extraHist[:]) - *(*[32]uint16)(w.literalFreq[256:]) = t.extraHist - w.offsetFreq = t.offHist + copy(w.literalFreq[:], t.litHist[:]) + copy(w.literalFreq[256:], t.extraHist[:]) + copy(w.offsetFreq[:], t.offHist[:offsetCodeCount]) if t.n == 0 { return diff --git a/huff0/decompress.go b/huff0/decompress.go index 42a237eac4..c0c48bd707 100644 --- a/huff0/decompress.go +++ b/huff0/decompress.go @@ -763,20 +763,17 @@ func (d *Decoder) decompress4X8bit(dst, src []byte) ([]byte, error) { d.bufs.Put(buf) return nil, errors.New("corruption detected: stream overrun 1") } + copy(out, buf[0][:]) + copy(out[dstEvery:], buf[1][:]) + copy(out[dstEvery*2:], buf[2][:]) + copy(out[dstEvery*3:], buf[3][:]) + out = out[bufoff:] + decoded += bufoff * 4 // There must at least be 3 buffers left. - if len(out)-bufoff < dstEvery*3 { + if len(out) < dstEvery*3 { d.bufs.Put(buf) return nil, errors.New("corruption detected: stream overrun 2") } - //copy(out, buf[0][:]) - //copy(out[dstEvery:], buf[1][:]) - //copy(out[dstEvery*2:], buf[2][:]) - *(*[bufoff]byte)(out) = buf[0] - *(*[bufoff]byte)(out[dstEvery:]) = buf[1] - *(*[bufoff]byte)(out[dstEvery*2:]) = buf[2] - *(*[bufoff]byte)(out[dstEvery*3:]) = buf[3] - out = out[bufoff:] - decoded += bufoff * 4 } } if off > 0 { @@ -1000,22 +997,17 @@ func (d *Decoder) decompress4X8bitExactly(dst, src []byte) ([]byte, error) { d.bufs.Put(buf) return nil, errors.New("corruption detected: stream overrun 1") } + copy(out, buf[0][:]) + copy(out[dstEvery:], buf[1][:]) + copy(out[dstEvery*2:], buf[2][:]) + copy(out[dstEvery*3:], buf[3][:]) + out = out[bufoff:] + decoded += bufoff * 4 // There must at least be 3 buffers left. - if len(out)-bufoff < dstEvery*3 { + if len(out) < dstEvery*3 { d.bufs.Put(buf) return nil, errors.New("corruption detected: stream overrun 2") } - - //copy(out, buf[0][:]) - //copy(out[dstEvery:], buf[1][:]) - //copy(out[dstEvery*2:], buf[2][:]) - // copy(out[dstEvery*3:], buf[3][:]) - *(*[bufoff]byte)(out) = buf[0] - *(*[bufoff]byte)(out[dstEvery:]) = buf[1] - *(*[bufoff]byte)(out[dstEvery*2:]) = buf[2] - *(*[bufoff]byte)(out[dstEvery*3:]) = buf[3] - out = out[bufoff:] - decoded += bufoff * 4 } } if off > 0 { diff --git a/huff0/decompress_generic.go b/huff0/decompress_generic.go index 908c17de63..4f6f37cb2c 100644 --- a/huff0/decompress_generic.go +++ b/huff0/decompress_generic.go @@ -122,21 +122,17 @@ func (d *Decoder) Decompress4X(dst, src []byte) ([]byte, error) { d.bufs.Put(buf) return nil, errors.New("corruption detected: stream overrun 1") } + copy(out, buf[0][:]) + copy(out[dstEvery:], buf[1][:]) + copy(out[dstEvery*2:], buf[2][:]) + copy(out[dstEvery*3:], buf[3][:]) + out = out[bufoff:] + decoded += bufoff * 4 // There must at least be 3 buffers left. - if len(out)-bufoff < dstEvery*3 { + if len(out) < dstEvery*3 { d.bufs.Put(buf) return nil, errors.New("corruption detected: stream overrun 2") } - //copy(out, buf[0][:]) - //copy(out[dstEvery:], buf[1][:]) - //copy(out[dstEvery*2:], buf[2][:]) - //copy(out[dstEvery*3:], buf[3][:]) - *(*[bufoff]byte)(out) = buf[0] - *(*[bufoff]byte)(out[dstEvery:]) = buf[1] - *(*[bufoff]byte)(out[dstEvery*2:]) = buf[2] - *(*[bufoff]byte)(out[dstEvery*3:]) = buf[3] - out = out[bufoff:] - decoded += bufoff * 4 } } if off > 0 { diff --git a/s2c b/s2c deleted file mode 100755 index 93b2942154..0000000000 Binary files a/s2c and /dev/null differ diff --git a/zstd/enc_dfast.go b/zstd/enc_dfast.go index 7d425109ad..a5158fc8fc 100644 --- a/zstd/enc_dfast.go +++ b/zstd/enc_dfast.go @@ -1099,8 +1099,7 @@ func (e *doubleFastEncoderDict) Reset(d *dict, singleBlock bool) { } if allDirty || dirtyShardCnt > dLongTableShardCnt/2 { - //copy(e.longTable[:], e.dictLongTable) - e.longTable = *(*[dFastLongTableSize]tableEntry)(e.dictLongTable) + copy(e.longTable[:], e.dictLongTable) for i := range e.longTableShardDirty { e.longTableShardDirty[i] = false } @@ -1111,9 +1110,7 @@ func (e *doubleFastEncoderDict) Reset(d *dict, singleBlock bool) { continue } - // copy(e.longTable[i*dLongTableShardSize:(i+1)*dLongTableShardSize], e.dictLongTable[i*dLongTableShardSize:(i+1)*dLongTableShardSize]) - *(*[dLongTableShardSize]tableEntry)(e.longTable[i*dLongTableShardSize:]) = *(*[dLongTableShardSize]tableEntry)(e.dictLongTable[i*dLongTableShardSize:]) - + copy(e.longTable[i*dLongTableShardSize:(i+1)*dLongTableShardSize], e.dictLongTable[i*dLongTableShardSize:(i+1)*dLongTableShardSize]) e.longTableShardDirty[i] = false } } diff --git a/zstd/enc_fast.go b/zstd/enc_fast.go index 315b1a8f2f..6bae3bb449 100644 --- a/zstd/enc_fast.go +++ b/zstd/enc_fast.go @@ -869,8 +869,7 @@ func (e *fastEncoderDict) Reset(d *dict, singleBlock bool) { const shardCnt = tableShardCnt const shardSize = tableShardSize if e.allDirty || dirtyShardCnt > shardCnt*4/6 { - //copy(e.table[:], e.dictTable) - e.table = *(*[tableSize]tableEntry)(e.dictTable) + copy(e.table[:], e.dictTable) for i := range e.tableShardDirty { e.tableShardDirty[i] = false } @@ -882,8 +881,7 @@ func (e *fastEncoderDict) Reset(d *dict, singleBlock bool) { continue } - //copy(e.table[i*shardSize:(i+1)*shardSize], e.dictTable[i*shardSize:(i+1)*shardSize]) - *(*[shardSize]tableEntry)(e.table[i*shardSize:]) = *(*[shardSize]tableEntry)(e.dictTable[i*shardSize:]) + copy(e.table[i*shardSize:(i+1)*shardSize], e.dictTable[i*shardSize:(i+1)*shardSize]) e.tableShardDirty[i] = false } e.allDirty = false