Skip to content

Commit

Permalink
improve copy performance
Browse files Browse the repository at this point in the history
  • Loading branch information
nitely committed Nov 16, 2024
1 parent ce8062c commit c31418d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/hyperx/utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,25 @@ template untrackExceptions*(body: untyped): untyped =
raise newException(Defect, err.msg)

func add*(s: var seq[byte], ss: openArray[char]) {.raises: [].} =
if ss.len == 0: return
let L = s.len
s.setLen(L+ss.len)
for i in 0 .. ss.len-1:
s[L+i] = ss[i].byte
when nimvm:
for i in 0 .. ss.len-1:
s[L+i] = ss[i].byte
else:
moveMem(addr s[L], unsafeAddr ss[0], ss.len)

func add*(s: var string, ss: openArray[byte]) {.raises: [].} =
if ss.len == 0: return
let L = s.len
s.setLen(L+ss.len)
for i in 0 .. ss.len-1:
s[L+i] = ss[i].char
when nimvm:
for i in 0 .. ss.len-1:
s[L+i] = ss[i].char
else:
prepareMutation(s)
moveMem(addr s[L], unsafeAddr ss[0], ss.len)

func parseBigInt(s: openArray[byte]): int64 {.raises: [ValueError].} =
if s.len == 0:
Expand Down

0 comments on commit c31418d

Please sign in to comment.