Remove deprecation warnings
This commit is contained in:
parent
e7a34b74f2
commit
5fb40e4ffd
2 changed files with 30 additions and 30 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
import
|
import
|
||||||
memfiles, options, stew/ranges/ptr_arith
|
memfiles, options, stew/[ptrops, ranges/ptr_arith]
|
||||||
|
|
||||||
const
|
const
|
||||||
pageSize = 4096
|
# pageSize = 4096
|
||||||
debugHelpers = false
|
debugHelpers = false
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
@ -44,7 +44,7 @@ proc openFile*(filename: string): ByteStreamVar =
|
||||||
result.head = cast[ptr byte](memFile.mem)
|
result.head = cast[ptr byte](memFile.mem)
|
||||||
when debugHelpers:
|
when debugHelpers:
|
||||||
result.bufferStart = result.head
|
result.bufferStart = result.head
|
||||||
result.bufferEnd = result.head.shift memFile.size
|
result.bufferEnd = offset(result.head, memFile.size)
|
||||||
result.bufferEndPos = memFile.size
|
result.bufferEndPos = memFile.size
|
||||||
result.closeStream = proc = close memFile
|
result.closeStream = proc = close memFile
|
||||||
|
|
||||||
|
|
@ -54,7 +54,7 @@ proc init*(T: type ByteStream,
|
||||||
asyncReader = AsyncStreamReader(nil)): ByteStream =
|
asyncReader = AsyncStreamReader(nil)): ByteStream =
|
||||||
# TODO: the result should use `from mem` once it's supported
|
# TODO: the result should use `from mem` once it's supported
|
||||||
result.head = unsafeAddr mem[0]
|
result.head = unsafeAddr mem[0]
|
||||||
result.bufferEnd = result.head.shift mem.len
|
result.bufferEnd = offset(result.head, mem.len)
|
||||||
result.bufferEndPos = mem.len
|
result.bufferEndPos = mem.len
|
||||||
result.reader = reader
|
result.reader = reader
|
||||||
result.asyncReader = asyncReader
|
result.asyncReader = asyncReader
|
||||||
|
|
@ -82,7 +82,7 @@ proc syncRead(s: var ByteStream): bool =
|
||||||
s.reader = nil
|
s.reader = nil
|
||||||
return true
|
return true
|
||||||
else:
|
else:
|
||||||
s.bufferEnd = s.bufferStart.shift bytesRead
|
s.bufferEnd = offset(s.bufferStart, bytesRead)
|
||||||
s.bufferEndPos += bytesRead
|
s.bufferEndPos += bytesRead
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
|
@ -118,7 +118,7 @@ when debugHelpers:
|
||||||
|
|
||||||
proc advance*(s: var ByteStream) =
|
proc advance*(s: var ByteStream) =
|
||||||
if s.head != s.bufferEnd:
|
if s.head != s.bufferEnd:
|
||||||
s.head = s.head.shift 1
|
s.head = offset(s.head, 1)
|
||||||
elif s.reader != nil:
|
elif s.reader != nil:
|
||||||
discard s.syncRead()
|
discard s.syncRead()
|
||||||
|
|
||||||
|
|
@ -129,7 +129,7 @@ proc read*(s: var ByteStream): byte =
|
||||||
proc checkReadAhead(s: ByteStreamVar, n: int): ptr byte =
|
proc checkReadAhead(s: ByteStreamVar, n: int): ptr byte =
|
||||||
result = s.head
|
result = s.head
|
||||||
doAssert distance(s.head, s.bufferEnd) >= n
|
doAssert distance(s.head, s.bufferEnd) >= n
|
||||||
s.head = s.head.shift(n)
|
s.head = offset(s.head, n)
|
||||||
|
|
||||||
template readBytes*(s: ByteStreamVar, n: int): auto =
|
template readBytes*(s: ByteStreamVar, n: int): auto =
|
||||||
makeOpenArray(checkReadAhead(s, n), n)
|
makeOpenArray(checkReadAhead(s, n), n)
|
||||||
|
|
@ -139,9 +139,9 @@ proc next*(s: var ByteStream): Option[byte] =
|
||||||
result = some s.read()
|
result = some s.read()
|
||||||
|
|
||||||
proc bufferPos(s: ByteStream, pos: int): ptr byte =
|
proc bufferPos(s: ByteStream, pos: int): ptr byte =
|
||||||
let shiftFromEnd = pos - s.bufferEndPos
|
let offsetFromEnd = pos - s.bufferEndPos
|
||||||
doAssert shiftFromEnd < 0
|
doAssert offsetFromEnd < 0
|
||||||
result = s.bufferEnd.shift shiftFromEnd
|
result = offset(s.bufferEnd, offsetFromEnd)
|
||||||
doAssert result >= s.bufferStart
|
doAssert result >= s.bufferStart
|
||||||
|
|
||||||
proc pos*(s: ByteStream): int {.inline.} =
|
proc pos*(s: ByteStream): int {.inline.} =
|
||||||
|
|
@ -154,7 +154,7 @@ proc `[]`*(s: ByteStream, pos: int): byte {.inline.} =
|
||||||
s.bufferPos(pos)[]
|
s.bufferPos(pos)[]
|
||||||
|
|
||||||
proc rewind*(s: var ByteStream, delta: int) =
|
proc rewind*(s: var ByteStream, delta: int) =
|
||||||
s.head = s.head.shift(-delta)
|
s.head = offset(s.head, -delta)
|
||||||
doAssert s.head >= s.bufferStart
|
doAssert s.head >= s.bufferStart
|
||||||
|
|
||||||
proc rewindTo*(s: var ByteStream, pos: int) {.inline.} =
|
proc rewindTo*(s: var ByteStream, pos: int) {.inline.} =
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import
|
import
|
||||||
deques, stew/ranges/ptr_arith, stew/strings
|
deques, stew/[ptrops, strings, ranges/ptr_arith]
|
||||||
|
|
||||||
type
|
type
|
||||||
OutputPage = object
|
OutputPage = object
|
||||||
|
|
@ -52,7 +52,7 @@ const
|
||||||
|
|
||||||
proc createWriteCursor*[R, T](x: var array[R, T]): WriteCursor =
|
proc createWriteCursor*[R, T](x: var array[R, T]): WriteCursor =
|
||||||
let startAddr = cast[ptr byte](addr x[0])
|
let startAddr = cast[ptr byte](addr x[0])
|
||||||
WriteCursor(head: startAddr, bufferEnd: shift(startAddr, sizeof x))
|
WriteCursor(head: startAddr, bufferEnd: offset(startAddr, sizeof x))
|
||||||
|
|
||||||
template canExtendOutput(s: OutputStreamVar): bool =
|
template canExtendOutput(s: OutputStreamVar): bool =
|
||||||
# Streams writing to pre-allocated existing buffers cannot be grown
|
# Streams writing to pre-allocated existing buffers cannot be grown
|
||||||
|
|
@ -69,7 +69,7 @@ proc flipPage(s: OutputStreamVar) =
|
||||||
s.cursor.head = cast[ptr byte](addr s.pages[s.pages.len - 1].buffer[0])
|
s.cursor.head = cast[ptr byte](addr s.pages[s.pages.len - 1].buffer[0])
|
||||||
# TODO: There is an assumption here and elsewhere that `s.pages[^1]` has
|
# TODO: There is an assumption here and elsewhere that `s.pages[^1]` has
|
||||||
# a length equal to `s.pageSize`
|
# a length equal to `s.pageSize`
|
||||||
s.cursor.bufferEnd = cast[ptr byte](shift(s.cursor.head, s.pageSize))
|
s.cursor.bufferEnd = cast[ptr byte](offset(s.cursor.head, s.pageSize))
|
||||||
s.endPos += s.pageSize
|
s.endPos += s.pageSize
|
||||||
|
|
||||||
proc addPage(s: OutputStreamVar) =
|
proc addPage(s: OutputStreamVar) =
|
||||||
|
|
@ -121,7 +121,7 @@ proc init*(T: type OutputStream,
|
||||||
new result
|
new result
|
||||||
let buffer = cast[ptr byte](buffer)
|
let buffer = cast[ptr byte](buffer)
|
||||||
result.cursor.head = buffer
|
result.cursor.head = buffer
|
||||||
result.cursor.bufferEnd = buffer.shift(len)
|
result.cursor.bufferEnd = offset(buffer, len)
|
||||||
result.cursor.stream = result
|
result.cursor.stream = result
|
||||||
result.endPos = len
|
result.endPos = len
|
||||||
|
|
||||||
|
|
@ -183,7 +183,7 @@ proc tryFlushing(s: OutputStreamVar) {.inline.} =
|
||||||
|
|
||||||
func endAddr(s: string): ptr byte {.inline.} =
|
func endAddr(s: string): ptr byte {.inline.} =
|
||||||
let a = unsafeAddr s[0]
|
let a = unsafeAddr s[0]
|
||||||
shift(cast[ptr byte](a), s.len)
|
offset(cast[ptr byte](a), s.len)
|
||||||
|
|
||||||
template startAddr(s: string): ptr byte =
|
template startAddr(s: string): ptr byte =
|
||||||
cast[ptr byte](unsafeAddr s[0])
|
cast[ptr byte](unsafeAddr s[0])
|
||||||
|
|
@ -203,7 +203,7 @@ proc findNextPage(c: var WriteCursor): int =
|
||||||
proc moveToPage(c: var WriteCursor, p: var OutputPage) =
|
proc moveToPage(c: var WriteCursor, p: var OutputPage) =
|
||||||
doAssert p.startOffset > 0
|
doAssert p.startOffset > 0
|
||||||
c.head = cast[ptr byte](unsafeAddr p.buffer[0])
|
c.head = cast[ptr byte](unsafeAddr p.buffer[0])
|
||||||
c.bufferEnd = shift(c.head, p.startOffset)
|
c.bufferEnd = offset(c.head, p.startOffset)
|
||||||
p.startOffset = 0
|
p.startOffset = 0
|
||||||
|
|
||||||
proc moveToNextPage(c: var WriteCursor) =
|
proc moveToNextPage(c: var WriteCursor) =
|
||||||
|
|
@ -218,7 +218,7 @@ proc append*(c: var WriteCursor, b: byte) =
|
||||||
c.stream.tryFlushing()
|
c.stream.tryFlushing()
|
||||||
|
|
||||||
c.head[] = b
|
c.head[] = b
|
||||||
c.head = shift(c.head, 1)
|
c.head = offset(c.head, 1)
|
||||||
|
|
||||||
template append*(c: var WriteCursor, x: char) =
|
template append*(c: var WriteCursor, x: char) =
|
||||||
bind append
|
bind append
|
||||||
|
|
@ -237,12 +237,12 @@ proc writeDataAsPages(s: OutputStreamVar, data: ptr byte, dataLen: int) =
|
||||||
|
|
||||||
while dataLen > s.pageSize:
|
while dataLen > s.pageSize:
|
||||||
s.vtable.writePage(s, makeOpenArray(data, s.pageSize))
|
s.vtable.writePage(s, makeOpenArray(data, s.pageSize))
|
||||||
data = shift(data, s.pageSize)
|
data = offset(data, s.pageSize)
|
||||||
dec dataLen, s.pageSize
|
dec dataLen, s.pageSize
|
||||||
s.endPos += s.pageSize
|
s.endPos += s.pageSize
|
||||||
|
|
||||||
copyMem(s.cursor.head, data, dataLen)
|
copyMem(s.cursor.head, data, dataLen)
|
||||||
s.cursor.head = shift(s.cursor.head, dataLen)
|
s.cursor.head = offset(s.cursor.head, dataLen)
|
||||||
|
|
||||||
proc newStringFromBytes(input: ptr byte, inputLen: int): string =
|
proc newStringFromBytes(input: ptr byte, inputLen: int): string =
|
||||||
assert inputLen > 0
|
assert inputLen > 0
|
||||||
|
|
@ -257,7 +257,7 @@ proc handleLongAppend*(c: var WriteCursor, bytes: openarray[byte]) =
|
||||||
stream = c.stream
|
stream = c.stream
|
||||||
|
|
||||||
template reduceInput(delta: int) =
|
template reduceInput(delta: int) =
|
||||||
inputPos = shift(inputPos, delta)
|
inputPos = offset(inputPos, delta)
|
||||||
inputLen -= delta
|
inputLen -= delta
|
||||||
|
|
||||||
# Since the input is longer, we first make sure that the top-most
|
# Since the input is longer, we first make sure that the top-most
|
||||||
|
|
@ -283,14 +283,14 @@ proc handleLongAppend*(c: var WriteCursor, bytes: openarray[byte]) =
|
||||||
if pageRunway < pageLen:
|
if pageRunway < pageLen:
|
||||||
doAssert inputLen <= pageRunway
|
doAssert inputLen <= pageRunway
|
||||||
copyMem(pageStart, inputPos, inputLen)
|
copyMem(pageStart, inputPos, inputLen)
|
||||||
c.head = shift(pageStart, inputLen)
|
c.head = offset(pageStart, inputLen)
|
||||||
c.bufferEnd = shift(pageStart, pageRunway)
|
c.bufferEnd = offset(pageStart, pageRunway)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if inputLen <= pageLen:
|
if inputLen <= pageLen:
|
||||||
copyMem(pageStart, inputPos, inputLen)
|
copyMem(pageStart, inputPos, inputLen)
|
||||||
c.head = shift(pageStart, inputLen)
|
c.head = offset(pageStart, inputLen)
|
||||||
c.bufferEnd = shift(pageStart, pageLen)
|
c.bufferEnd = offset(pageStart, pageLen)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
copyMem(pageStart, inputPos, pageLen)
|
copyMem(pageStart, inputPos, pageLen)
|
||||||
|
|
@ -343,7 +343,7 @@ proc handleLongAppend*(c: var WriteCursor, bytes: openarray[byte]) =
|
||||||
# This will also reset the cursor to the start of the page:
|
# This will also reset the cursor to the start of the page:
|
||||||
stream.addPage
|
stream.addPage
|
||||||
copyMem(c.head, inputPos, inputLen)
|
copyMem(c.head, inputPos, inputLen)
|
||||||
c.head = shift(c.head, inputLen)
|
c.head = offset(c.head, inputLen)
|
||||||
# We must correct endPos, because it must mark the end of the top-most
|
# We must correct endPos, because it must mark the end of the top-most
|
||||||
# page. Since `addPage` advances the endPos as well and our remaining
|
# page. Since `addPage` advances the endPos as well and our remaining
|
||||||
# input was written to the newly created page, our initial increase of
|
# input was written to the newly created page, our initial increase of
|
||||||
|
|
@ -361,7 +361,7 @@ proc append*(c: var WriteCursor, bytes: openarray[byte]) {.inline.} =
|
||||||
if inputLen == 0: return
|
if inputLen == 0: return
|
||||||
if inputLen <= pageRemaining:
|
if inputLen <= pageRemaining:
|
||||||
copyMem(c.head, unsafeAddr bytes[0], inputLen)
|
copyMem(c.head, unsafeAddr bytes[0], inputLen)
|
||||||
c.head = shift(c.head, inputLen)
|
c.head = offset(c.head, inputLen)
|
||||||
else:
|
else:
|
||||||
handleLongAppend(c, bytes)
|
handleLongAppend(c, bytes)
|
||||||
|
|
||||||
|
|
@ -417,7 +417,7 @@ proc createCursor(s: OutputStreamVar, size: int): WriteCursor =
|
||||||
inc s.extCursorsCount
|
inc s.extCursorsCount
|
||||||
|
|
||||||
result = WriteCursor(head: s.cursor.head,
|
result = WriteCursor(head: s.cursor.head,
|
||||||
bufferEnd: s.cursor.head.shift(size),
|
bufferEnd: offset(s.cursor.head, size),
|
||||||
stream: s)
|
stream: s)
|
||||||
|
|
||||||
s.cursor.head = result.bufferEnd
|
s.cursor.head = result.bufferEnd
|
||||||
|
|
@ -439,7 +439,7 @@ proc delayFixedSizeWrite*(s: OutputStreamVar, size: Natural): WriteCursor =
|
||||||
startOffset: size)
|
startOffset: size)
|
||||||
|
|
||||||
let (pageStart, pageEnd) = boundingAddrs s.pages[s.pages.len - 1].buffer
|
let (pageStart, pageEnd) = boundingAddrs s.pages[s.pages.len - 1].buffer
|
||||||
s.cursor.head = shift(pageStart, size)
|
s.cursor.head = offset(pageStart, size)
|
||||||
s.cursor.bufferEnd = pageEnd
|
s.cursor.bufferEnd = pageEnd
|
||||||
s.endPos += (s.pageSize - size)
|
s.endPos += (s.pageSize - size)
|
||||||
|
|
||||||
|
|
@ -465,7 +465,7 @@ proc writeAndFinalize*(c: var VarSizeWriteCursor, data: openarray[byte]) =
|
||||||
let overestimatedBytes = cursor.runway - data.len
|
let overestimatedBytes = cursor.runway - data.len
|
||||||
doAssert overestimatedBytes >= 0
|
doAssert overestimatedBytes >= 0
|
||||||
page.startOffset = overestimatedBytes
|
page.startOffset = overestimatedBytes
|
||||||
copyMem(cursor.head.shift(overestimatedBytes), unsafeAddr data[0], data.len)
|
copyMem(offset(cursor.head, overestimatedBytes), unsafeAddr data[0], data.len)
|
||||||
finalize cursor
|
finalize cursor
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue