From a50985ff8d478f1158d9ef2907f44e90a16f791e Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Sun, 8 Nov 2020 17:34:09 -0600 Subject: [PATCH] formatting --- examples/http_client.nim | 4 ++-- examples/http_server.nim | 4 ++-- src/zippy/common.nim | 2 +- src/zippy/deflate.nim | 2 +- tests/lz77.nim | 17 ++++++++--------- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/examples/http_client.nim b/examples/http_client.nim index b5d4ddd..ba869cd 100644 --- a/examples/http_client.nim +++ b/examples/http_client.nim @@ -1,7 +1,7 @@ -import httpclient, zippy, strformat +import httpclient, strformat, zippy let client = newHttpClient() -client.headers = newHttpHeaders({ "Accept-Encoding": "gzip" }) +client.headers = newHttpHeaders({"Accept-Encoding": "gzip"}) let response = client.request("http://www.google.com") diff --git a/examples/http_server.nim b/examples/http_server.nim index 5d46b45..6143909 100644 --- a/examples/http_server.nim +++ b/examples/http_server.nim @@ -1,11 +1,11 @@ -import asynchttpserver, asyncdispatch, zippy +import asyncdispatch, asynchttpserver, zippy let server = newAsyncHttpServer() proc cb(req: Request) {.async.} = if req.headers["Accept-Encoding"].contains("gzip"): # This client supports gzip, send compressed response - let headers = newHttpHeaders([("Content-Encoding","gzip")]) + let headers = newHttpHeaders([("Content-Encoding", "gzip")]) await req.respond( Http200, compress("gzip'ed response body", dfGzip), diff --git a/src/zippy/common.nim b/src/zippy/common.nim index e4935c2..0551da9 100644 --- a/src/zippy/common.nim +++ b/src/zippy/common.nim @@ -1,5 +1,5 @@ const - maxCodeLength* = 15 ## Maximum bits in a code + maxCodeLength* = 15 ## Maximum bits in a code maxLitLenCodes* = 286 maxDistCodes* = 30 maxFixedLitLenCodes* = 288 diff --git a/src/zippy/deflate.nim b/src/zippy/deflate.nim index f629754..fe9a1c7 100644 --- a/src/zippy/deflate.nim +++ b/src/zippy/deflate.nim @@ -234,7 +234,7 @@ func lz77Encode(src: seq[uint8]): (seq[uint16], seq[int], seq[int], int) = var pos, literalLen: int windowPos, hash: uint16 - head = newSeq[uint16](hashSize) # hash -> pos + head = newSeq[uint16](hashSize) # hash -> pos chain = newSeq[uint16](windowSize) # pos a -> pos b template updateHash(value: uint8) = diff --git a/tests/lz77.nim b/tests/lz77.nim index ce1c29d..e862f94 100644 --- a/tests/lz77.nim +++ b/tests/lz77.nim @@ -1,4 +1,4 @@ -import strformat, strutils, fidget/opengl/perf +import fidget/opengl/perf, strformat, strutils const minMatchLen = 3 @@ -47,7 +47,7 @@ proc lz77Encode2(src: seq[uint8]): seq[uint16] = var pos, literalLen: int windowPos, hash: uint16 - head = newSeq[uint16](hashSize) # hash -> pos + head = newSeq[uint16](hashSize) # hash -> pos chain = newSeq[uint16](windowSize) # pos a -> pos b template updateHash(value: uint8) = @@ -82,12 +82,11 @@ proc lz77Encode2(src: seq[uint8]): seq[uint16] = break inc chainLen - let offset = ( - if hashPos <= windowPos: - windowPos - hashPos - else: - windowPos - hashPos + windowSize - ).int + var offset: int + if hashPos <= windowPos: + offset = (windowPos - hashPos).int + else: + offset = (windowPos - hashPos + windowSize).int if offset <= 0 or offset < prevOffset: break @@ -136,7 +135,7 @@ proc lz77Decode2(src: seq[uint8], encoded: seq[uint16]): seq[uint8] = var ip, op: int while ip < encoded.len: if op >= result.len: - result.setLen(result.len * 2) + result.setLen(result.len * 2) if encoded[ip] == uint16.high: let