make test green
This commit is contained in:
parent
d954859d58
commit
4378d9fc93
26
snappy.nim
26
snappy.nim
|
@ -68,6 +68,7 @@ func load64(b: openArray[byte]): uint64 {.inline.} =
|
|||
func load64(b: openArray[byte], i: int): uint64 =
|
||||
result = load64(b[i..<i+8])
|
||||
|
||||
import typetraits
|
||||
# emitLiteral writes a literal chunk.
|
||||
#
|
||||
# It assumes that:
|
||||
|
@ -79,11 +80,11 @@ proc emitLiteral(s: OutputStreamVar, lit: openarray[byte]) =
|
|||
s.append (byte(n) shl 2) or tagLiteral
|
||||
elif n < (1 shl 8):
|
||||
s.append (60 shl 2) or tagLiteral
|
||||
s.append byte(n)
|
||||
s.append byte(n and 0xFF)
|
||||
else:
|
||||
s.append (61 shl 2) or tagLiteral
|
||||
s.append byte(n)
|
||||
s.append byte(n shr 8)
|
||||
s.append byte(n and 0xFF)
|
||||
s.append byte((n shr 8) and 0xFF)
|
||||
|
||||
s.append lit
|
||||
|
||||
|
@ -106,27 +107,26 @@ proc emitCopy(s: OutputStreamVar, offset, length: int) =
|
|||
while length >= 68:
|
||||
# Emit a length 64 copy, encoded as 3 bytes.
|
||||
s.append (63 shl 2) or tagCopy2
|
||||
s.append byte(offset)
|
||||
s.append byte(offset shr 8)
|
||||
s.append byte(offset and 0xFF)
|
||||
s.append byte((offset shr 8) and 0xFF)
|
||||
dec(length, 64)
|
||||
|
||||
if length > 64:
|
||||
# Emit a length 60 copy, encoded as 3 bytes.
|
||||
s.append (59 shl 2) or tagCopy2
|
||||
s.append byte(offset)
|
||||
s.append byte(offset shr 8)
|
||||
s.append byte(offset and 0xFF)
|
||||
s.append byte((offset shr 8) and 0xFF)
|
||||
dec(length, 60)
|
||||
|
||||
if (length >= 12) or (offset >= 2048):
|
||||
# Emit the remaining copy, encoded as 3 bytes.
|
||||
s.append (byte(length-1) shl 2) or tagCopy2
|
||||
s.append byte(offset)
|
||||
s.append byte(offset shr 8)
|
||||
s.append byte((((length-1) shl 2) or tagCopy2) and 0xFF)
|
||||
s.append byte(offset and 0xFF)
|
||||
s.append byte((offset shr 8) and 0xFF)
|
||||
return
|
||||
|
||||
# Emit the remaining copy, encoded as 2 bytes.
|
||||
s.append (byte(offset shr 8) shl 5) or (byte(length-4) shl 2) or tagCopy1
|
||||
s.append byte(offset)
|
||||
s.append byte((((offset shr 8) shl 5) or ((length-4) shl 2) or tagCopy1) and 0xFF)
|
||||
s.append byte(offset and 0xFF)
|
||||
|
||||
when false:
|
||||
# extendMatch returns the largest k such that k <= len(src) and that
|
||||
|
|
|
@ -89,8 +89,8 @@ proc emitLiteral(s: Stream, lit: openarray[byte]) =
|
|||
s.writeByte byte(n)
|
||||
else:
|
||||
s.writeByte (61 shl 2) or tagLiteral
|
||||
s.writeByte byte(n)
|
||||
s.writeByte byte(n shr 8)
|
||||
s.writeByte byte(n and 0xFF)
|
||||
s.writeByte byte((n shr 8) and 0xFF)
|
||||
|
||||
s.writeBytes lit
|
||||
|
||||
|
@ -113,27 +113,26 @@ proc emitCopy(s: Stream, offset, length: int) =
|
|||
while length >= 68:
|
||||
# Emit a length 64 copy, encoded as 3 bytes.
|
||||
s.writeByte (63 shl 2) or tagCopy2
|
||||
s.writeByte byte(offset)
|
||||
s.writeByte byte(offset shr 8)
|
||||
s.writeByte byte(offset and 0xFF)
|
||||
s.writeByte byte((offset shr 8) and 0xFF)
|
||||
dec(length, 64)
|
||||
|
||||
if length > 64:
|
||||
# Emit a length 60 copy, encoded as 3 bytes.
|
||||
s.writeByte (59 shl 2) or tagCopy2
|
||||
s.writeByte byte(offset)
|
||||
s.writeByte byte(offset shr 8)
|
||||
s.writeByte byte(offset and 0xFF)
|
||||
s.writeByte byte((offset shr 8) and 0xFF)
|
||||
dec(length, 60)
|
||||
|
||||
if (length >= 12) or (offset >= 2048):
|
||||
# Emit the remaining copy, encoded as 3 bytes.
|
||||
s.writeByte (byte(length-1) shl 2) or tagCopy2
|
||||
s.writeByte byte(offset)
|
||||
s.writeByte byte(offset shr 8)
|
||||
s.writeByte byte((((length-1) shl 2) or tagCopy2) and 0xFF)
|
||||
s.writeByte byte(offset and 0xFF)
|
||||
s.writeByte byte((offset shr 8) and 0xFF)
|
||||
return
|
||||
|
||||
# Emit the remaining copy, encoded as 2 bytes.
|
||||
s.writeByte (byte(offset shr 8) shl 5) or (byte(length-4) shl 2) or tagCopy1
|
||||
s.writeByte byte(offset)
|
||||
s.writeByte byte((((offset shr 8) shl 5) or ((length-4) shl 2) or tagCopy1) and 0xFF)
|
||||
s.writeByte byte(offset and 0xFF)
|
||||
|
||||
when false:
|
||||
# extendMatch returns the largest k such that k <= len(src) and that
|
||||
|
|
|
@ -89,8 +89,8 @@ func emitLiteral(dst: var openArray[byte], lit: openArray[byte]): int =
|
|||
i = 2
|
||||
else:
|
||||
dst[0] = (61 shl 2) or tagLiteral
|
||||
dst[1] = byte(n)
|
||||
dst[2] = byte(n shr 8)
|
||||
dst[1] = byte(n and 0xFF)
|
||||
dst[2] = byte((n shr 8) and 0xFF)
|
||||
i = 3
|
||||
|
||||
copyMem(dst[i].addr, lit[0].unsafeAddr, lit.len)
|
||||
|
@ -119,29 +119,29 @@ func emitCopy(dst: var openArray[byte], offset, length: int): int =
|
|||
while length >= 68:
|
||||
# Emit a length 64 copy, encoded as 3 bytes.
|
||||
dst[i+0] = (63 shl 2) or tagCopy2
|
||||
dst[i+1] = byte(offset)
|
||||
dst[i+2] = byte(offset shr 8)
|
||||
dst[i+1] = byte(offset and 0xFF)
|
||||
dst[i+2] = byte((offset shr 8) and 0xFF)
|
||||
inc(i, 3)
|
||||
dec(length, 64)
|
||||
|
||||
if length > 64:
|
||||
# Emit a length 60 copy, encoded as 3 bytes.
|
||||
dst[i+0] = (59 shl 2) or tagCopy2
|
||||
dst[i+1] = byte(offset)
|
||||
dst[i+2] = byte(offset shr 8)
|
||||
dst[i+1] = byte(offset and 0xFF)
|
||||
dst[i+2] = byte((offset shr 8) and 0xFF)
|
||||
inc(i, 3)
|
||||
dec(length, 60)
|
||||
|
||||
if (length >= 12) or (offset >= 2048):
|
||||
# Emit the remaining copy, encoded as 3 bytes.
|
||||
dst[i+0] = (byte(length-1) shl 2) or tagCopy2
|
||||
dst[i+1] = byte(offset)
|
||||
dst[i+2] = byte(offset shr 8)
|
||||
dst[i+1] = byte(offset and 0xFF)
|
||||
dst[i+2] = byte((offset shr 8) and 0xFF)
|
||||
return i + 3
|
||||
|
||||
# Emit the remaining copy, encoded as 2 bytes.
|
||||
dst[i+0] = (byte(offset shr 8) shl 5) or (byte(length-4) shl 2) or tagCopy1
|
||||
dst[i+1] = byte(offset)
|
||||
dst[i+0] = byte((((offset shr 8) shl 5) or ((length-4) shl 2) or tagCopy1) and 0xFF)
|
||||
dst[i+1] = byte(offset and 0xFF)
|
||||
result = i + 2
|
||||
|
||||
when false:
|
||||
|
|
|
@ -142,7 +142,8 @@ proc roundTripRev(msg: string, sourceName: string): bool =
|
|||
template toBytes(s: string): auto =
|
||||
toOpenArrayByte(s, 0, s.len-1)
|
||||
|
||||
proc compressFileWithFaststreams(src, dst: string) =
|
||||
when false:
|
||||
proc compressFileWithFaststreams(src, dst: string) =
|
||||
var input = faststreams.openFile(src)
|
||||
var output = OutputStream.init(dst)
|
||||
output.appendSnappyBytes input.readBytes(input.endPos - 1)
|
||||
|
|
Loading…
Reference in New Issue