Enable --styleCheck:usages
This commit is contained in:
parent
1b561a9e71
commit
1f62235d4f
9 changed files with 39 additions and 37 deletions
|
|
@ -55,7 +55,7 @@ else:
|
|||
template describeBuffers*(context: static string, buffers: PageBuffers) =
|
||||
discard
|
||||
|
||||
func openArrayToPair*(a: var openarray[byte]): (ptr byte, Natural) =
|
||||
func openArrayToPair*(a: var openArray[byte]): (ptr byte, Natural) =
|
||||
(addr a[0], Natural(a.len))
|
||||
|
||||
template allocationStart*(page: PageRef): ptr byte =
|
||||
|
|
|
|||
|
|
@ -424,7 +424,7 @@ proc fileInput*(filename: string,
|
|||
buffers: initPageBuffers(pageSize),
|
||||
file: file)
|
||||
|
||||
proc unsafeMemoryInput*(mem: openarray[byte]): InputStreamHandle =
|
||||
proc unsafeMemoryInput*(mem: openArray[byte]): InputStreamHandle =
|
||||
let head = unsafeAddr mem[0]
|
||||
|
||||
makeHandle InputStream(
|
||||
|
|
@ -457,7 +457,7 @@ func memoryInput*(buffers: PageBuffers): InputStreamHandle =
|
|||
span: span,
|
||||
spanEndPos: spanEndPos)
|
||||
|
||||
func memoryInput*(data: openarray[byte]): InputStreamHandle =
|
||||
func memoryInput*(data: openArray[byte]): InputStreamHandle =
|
||||
let stream = if data.len > 0:
|
||||
let
|
||||
buffers = initPageBuffers(data.len)
|
||||
|
|
@ -474,7 +474,7 @@ func memoryInput*(data: openarray[byte]): InputStreamHandle =
|
|||
|
||||
makeHandle stream
|
||||
|
||||
func memoryInput*(data: openarray[char]): InputStreamHandle =
|
||||
func memoryInput*(data: openArray[char]): InputStreamHandle =
|
||||
memoryInput charsToBytes(data)
|
||||
|
||||
proc resetBuffers*(s: InputStream, buffers: PageBuffers) =
|
||||
|
|
@ -812,7 +812,7 @@ template readIntoExImpl(s: InputStream,
|
|||
|
||||
dstLen - bytesDeficit
|
||||
|
||||
proc readIntoEx*(s: InputStream, dst: var openarray[byte]): int =
|
||||
proc readIntoEx*(s: InputStream, dst: var openArray[byte]): int =
|
||||
## Read data into the destination buffer.
|
||||
##
|
||||
## Returns the number of bytes that were successfully
|
||||
|
|
@ -823,7 +823,7 @@ proc readIntoEx*(s: InputStream, dst: var openarray[byte]): int =
|
|||
let dstLen = dst.len
|
||||
readIntoExImpl(s, dstAddr, dstLen, noAwait, readSync)
|
||||
|
||||
proc readInto*(s: InputStream, target: var openarray[byte]): bool =
|
||||
proc readInto*(s: InputStream, target: var openArray[byte]): bool =
|
||||
## Read data into the destination buffer.
|
||||
##
|
||||
## Returns `false` if EOF was reached before the buffer
|
||||
|
|
@ -832,14 +832,14 @@ proc readInto*(s: InputStream, target: var openarray[byte]): bool =
|
|||
s.readIntoEx(target) == target.len
|
||||
|
||||
when fsAsyncSupport:
|
||||
template readIntoEx*(sp: AsyncInputStream, dst: var openarray[byte]): int =
|
||||
template readIntoEx*(sp: AsyncInputStream, dst: var openArray[byte]): int =
|
||||
let s = InputStream(sp)
|
||||
# BEWARE! `openArrayToPair` here is needed to avoid
|
||||
# double evaluation of the `dst` expression:
|
||||
let (dstAddr, dstLen) = openArrayToPair(dst)
|
||||
readIntoExImpl(s, dstAddr, dstLen, fsAwait, readAsync)
|
||||
|
||||
template readInto*(sp: AsyncInputStream, dst: var openarray[byte]): bool =
|
||||
template readInto*(sp: AsyncInputStream, dst: var openArray[byte]): bool =
|
||||
## Asynchronously read data into the destination buffer.
|
||||
##
|
||||
## Returns `false` if EOF was reached before the buffer
|
||||
|
|
@ -871,7 +871,7 @@ template useStackMem(n: static Natural) =
|
|||
|
||||
template readNImpl(sp: InputStream,
|
||||
np: Natural,
|
||||
createAllocMemOp: untyped): openarray[byte] =
|
||||
createAllocMemOp: untyped): openArray[byte] =
|
||||
let
|
||||
s = sp
|
||||
n = np
|
||||
|
|
@ -881,7 +881,7 @@ template readNImpl(sp: InputStream,
|
|||
# to appear in different branches of an if statement, the code must
|
||||
# be written in this branch-free linear fashion. The `dataCopy` seq
|
||||
# may remain empty in the case where we use stack memory or return
|
||||
# an `openarray` from the existing span.
|
||||
# an `openArray` from the existing span.
|
||||
var startAddr: ptr byte
|
||||
|
||||
block:
|
||||
|
|
@ -902,21 +902,21 @@ template readNImpl(sp: InputStream,
|
|||
|
||||
makeOpenArray(startAddr, n)
|
||||
|
||||
template read*(sp: InputStream, np: static Natural): openarray[byte] =
|
||||
template read*(sp: InputStream, np: static Natural): openArray[byte] =
|
||||
const n = np
|
||||
when n < maxStackUsage:
|
||||
readNImpl(sp, n, useStackMem)
|
||||
else:
|
||||
readNImpl(sp, n, useHeapMem)
|
||||
|
||||
template read*(s: InputStream, n: Natural): openarray[byte] =
|
||||
template read*(s: InputStream, n: Natural): openArray[byte] =
|
||||
readNImpl(s, n, useHeapMem)
|
||||
|
||||
when fsAsyncSupport:
|
||||
template read*(s: AsyncInputStream, n: Natural): openarray[byte] =
|
||||
template read*(s: AsyncInputStream, n: Natural): openArray[byte] =
|
||||
read InputStream(s), n
|
||||
|
||||
proc lookAheadMatch*(s: InputStream, data: openarray[byte]): bool =
|
||||
proc lookAheadMatch*(s: InputStream, data: openArray[byte]): bool =
|
||||
for i in 0 ..< data.len:
|
||||
if s.peekAt(i) != data[i]:
|
||||
return false
|
||||
|
|
@ -924,7 +924,7 @@ proc lookAheadMatch*(s: InputStream, data: openarray[byte]): bool =
|
|||
return true
|
||||
|
||||
when fsAsyncSupport:
|
||||
template lookAheadMatch*(s: AsyncInputStream, data: openarray[byte]): bool =
|
||||
template lookAheadMatch*(s: AsyncInputStream, data: openArray[byte]): bool =
|
||||
lookAheadMatch InputStream(s)
|
||||
|
||||
proc next*(s: InputStream): Option[byte] =
|
||||
|
|
|
|||
|
|
@ -652,13 +652,13 @@ proc writeMemCopy*(s: OutputStream, value: auto) =
|
|||
|
||||
when fsAsyncSupport:
|
||||
proc writeBytesAsyncImpl(sp: OutputStream,
|
||||
bytes: openarray[byte]): Future[void] =
|
||||
bytes: openArray[byte]): Future[void] =
|
||||
let s = sp
|
||||
writeBytesImpl(s, bytes):
|
||||
return s.vtable.writeAsync(s, unsafeAddr bytes[0], bytes.len)
|
||||
|
||||
proc writeBytesAsyncImpl(s: OutputStream,
|
||||
chars: openarray[char]): Future[void] =
|
||||
chars: openArray[char]): Future[void] =
|
||||
writeBytesAsyncImpl s, charsToBytes(chars)
|
||||
|
||||
proc writeBytesAsyncImpl(s: OutputStream,
|
||||
|
|
@ -684,7 +684,7 @@ when fsAsyncSupport:
|
|||
template writeMemCopyAndWait*(sp: AsyncOutputStream, value: auto) =
|
||||
writeAndWait(sp, memCopyToBytes(value))
|
||||
|
||||
proc writeBytesToCursor(c: var WriteCursor, bytes: openarray[byte]) =
|
||||
proc writeBytesToCursor(c: var WriteCursor, bytes: openArray[byte]) =
|
||||
var
|
||||
runway = c.span.len
|
||||
inputPos = unsafeAddr bytes[0]
|
||||
|
|
@ -713,11 +713,11 @@ proc writeBytesToCursor(c: var WriteCursor, bytes: openarray[byte]) =
|
|||
copyMem(c.span.startAddr, inputPos, inputLen)
|
||||
c.span.startAddr = offset(c.span.startAddr, inputLen)
|
||||
|
||||
template write*(c: var WriteCursor, bytes: openarray[byte]) =
|
||||
template write*(c: var WriteCursor, bytes: openArray[byte]) =
|
||||
bind writeBytesToCursor
|
||||
writeBytesToCursor(c, bytes)
|
||||
|
||||
proc write*(c: var WriteCursor, chars: openarray[char]) {.inline.} =
|
||||
proc write*(c: var WriteCursor, chars: openArray[char]) {.inline.} =
|
||||
var charsStart = unsafeAddr chars[0]
|
||||
writeBytesToCursor(c, makeOpenArray(cast[ptr byte](charsStart), chars.len))
|
||||
|
||||
|
|
@ -749,7 +749,7 @@ template consumeOutputs*(s: OutputStream, bytesVar, body: untyped) =
|
|||
##
|
||||
## Before consuming the outputs, all outstanding delayed writes must
|
||||
## be finalized.
|
||||
proc consumer(bytesVar: openarray[byte]) {.gcsafe, raises: [Defect].} =
|
||||
proc consumer(bytesVar: openArray[byte]) {.gcsafe, raises: [Defect].} =
|
||||
body
|
||||
|
||||
consumeOutputsImpl(s, consumer)
|
||||
|
|
@ -795,7 +795,7 @@ template consumeContiguousOutput*(s: OutputStream, bytesVar, body: untyped) =
|
|||
## Before consuming the output, all outstanding delayed writes must
|
||||
## be finalized.
|
||||
##
|
||||
proc consumer(bytesVar: openarray[byte]) {.gcsafe, raises: [Defect].} =
|
||||
proc consumer(bytesVar: openArray[byte]) {.gcsafe, raises: [Defect].} =
|
||||
body
|
||||
|
||||
consumeContiguousOutputImpl(s, consumer)
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ proc writeText*(s: OutputStream, x: CompiledIntTypes) =
|
|||
writeText(s, MatchingUInt(x))
|
||||
|
||||
when defined(c):
|
||||
|
||||
|
||||
proc writeText*(s: OutputStream, x: float64|float32|float) =
|
||||
## Write the floating point number to the output stream. It has less overhead
|
||||
## than `$` because it is directly written to the stream without
|
||||
|
|
@ -112,14 +112,14 @@ template writeText*(s: OutputStream, str: string) =
|
|||
template writeText*(s: OutputStream, val: auto) =
|
||||
write s, $val
|
||||
|
||||
proc writeHex*(s: OutputStream, bytes: openarray[byte]) =
|
||||
proc writeHex*(s: OutputStream, bytes: openArray[byte]) =
|
||||
const hexChars = "0123456789abcdef"
|
||||
|
||||
for b in bytes:
|
||||
s.write hexChars[int b shr 4 and 0xF]
|
||||
s.write hexChars[int b and 0xF]
|
||||
|
||||
proc writeHex*(s: OutputStream, chars: openarray[char]) =
|
||||
proc writeHex*(s: OutputStream, chars: openArray[char]) =
|
||||
writeHex s, charsToBytes(chars)
|
||||
|
||||
const
|
||||
|
|
@ -145,7 +145,7 @@ proc readLine*(s: InputStream, keepEol = false): TaintedString {.fsMultiSync.} =
|
|||
result.add s.read.char
|
||||
|
||||
proc readUntil*(s: InputStream,
|
||||
sep: openarray[char]): Option[TaintedString] =
|
||||
sep: openArray[char]): Option[TaintedString] =
|
||||
fsAssert readableNow(s)
|
||||
var res = ""
|
||||
while s.readable(sep.len):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue