File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed
Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -370,7 +370,7 @@ func encodeBlockBestSnappy(dst, src []byte) (d int) {
370370 }
371371 offset := m .s - m .offset
372372
373- return score - emitCopySize (offset , m .length )
373+ return score - emitCopyNoRepeatSize (offset , m .length )
374374 }
375375
376376 matchAt := func (offset , s int , first uint32 ) match {
@@ -581,6 +581,28 @@ func emitCopySize(offset, length int) int {
581581 return 2
582582}
583583
584+ // emitCopyNoRepeatSize returns the size to encode the offset+length
585+ //
586+ // It assumes that:
587+ // 1 <= offset && offset <= math.MaxUint32
588+ // 4 <= length && length <= 1 << 24
589+ func emitCopyNoRepeatSize (offset , length int ) int {
590+ if offset >= 65536 {
591+ return 5 + 5 * (length / 64 )
592+ }
593+
594+ // Offset no more than 2 bytes.
595+ if length > 64 {
596+ // Emit remaining as repeats, at least 4 bytes remain.
597+ return 3 + 3 * (length / 60 )
598+ }
599+ if length >= 12 || offset >= 2048 {
600+ return 3
601+ }
602+ // Emit the remaining copy, encoded as 2 bytes.
603+ return 2
604+ }
605+
584606// emitRepeatSize returns the number of bytes required to encode a repeat.
585607// Length must be at least 4 and < 1<<24
586608func emitRepeatSize (offset , length int ) int {
You can’t perform that action at this time.
0 commit comments