Skip to content

Commit

Permalink
Optimize object ownership
Browse files Browse the repository at this point in the history
  • Loading branch information
dadadani committed Aug 23, 2023
1 parent ed48d3c commit 530143b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/tltypes/private/stream.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type TLStream* = ref object
## A stream of bytes
stream: seq[uint8] ## Sequence of bytes

proc newTLStream*(data: seq[uint8]): TLStream =
proc newTLStream*(data: sink seq[uint8]): TLStream =
## Create a new TLStream
return TLStream(stream: data)

Expand All @@ -31,7 +31,7 @@ proc readBytes*(self: TLStream, n: uint): seq[uint8] =
proc len*(self: TLStream): int =
return self.stream.len

proc readAll*(self: TLStream): seq[uint8] =
proc readAll*(self: sink TLStream): seq[uint8] =
## Read everything remaining
result = self.stream
self.stream.setLen(0)
Expand Down
5 changes: 2 additions & 3 deletions writer/decode.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ proc generateDecode*(file: File, constructors: seq[TLConstructor],
if log: stdout.styledWriteLine(fgCyan, styleBright, " Info:",
fgDefault,
resetStyle, " Generating TLDecode")
file.write("\n\nproc TLDecode*(stream: TLStream): TL =")
file.write("\n\nproc TLDecode*(stream: sink TLStream): TL =")
file.write("\n case TLDecode[uint32](stream):")

for constructor in constructors:
Expand Down Expand Up @@ -110,8 +110,7 @@ proc generateDecode*(file: File, constructors: seq[TLConstructor],
of uint32(0x1cb5c415):
let length = TLDecode[int32](stream)
let buffer = stream.readAll()
var stream = newTLStream(buffer)
let elementsLength = len(buffer) / length
let elementsLength = len(stream) / length
result = TLVector(constructorID: 0x1cb5c415)
if elementsLength == 4:
for _ in 0..<length:
Expand Down

0 comments on commit 530143b

Please sign in to comment.