sizeof(char) is always 1
This commit is contained in:
parent
0264b42216
commit
d875951124
3 changed files with 10 additions and 10 deletions
|
|
@ -36,7 +36,7 @@ proc copyDeepString(src: NimString): NimString {.inline.} =
|
||||||
if src != nil:
|
if src != nil:
|
||||||
result = rawNewStringNoInit(src.len)
|
result = rawNewStringNoInit(src.len)
|
||||||
result.len = src.len
|
result.len = src.len
|
||||||
c_memcpy(result.data, src.data, (src.len + 1) * sizeof(char))
|
c_memcpy(result.data, src.data, src.len + 1)
|
||||||
|
|
||||||
proc genericDeepCopyAux(dest, src: pointer, mt: PNimType) =
|
proc genericDeepCopyAux(dest, src: pointer, mt: PNimType) =
|
||||||
var
|
var
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ proc usrToCell(usr: pointer): PCell {.inline.} =
|
||||||
# convert pointer to userdata to object (=pointer to refcount)
|
# convert pointer to userdata to object (=pointer to refcount)
|
||||||
result = cast[PCell](cast[ByteAddress](usr)-%ByteAddress(sizeof(TCell)))
|
result = cast[PCell](cast[ByteAddress](usr)-%ByteAddress(sizeof(TCell)))
|
||||||
|
|
||||||
proc canbeCycleRoot(c: PCell): bool {.inline.} =
|
proc canBeCycleRoot(c: PCell): bool {.inline.} =
|
||||||
result = ntfAcyclic notin c.typ.flags
|
result = ntfAcyclic notin c.typ.flags
|
||||||
|
|
||||||
proc extGetCellType(c: pointer): PNimType {.compilerproc.} =
|
proc extGetCellType(c: pointer): PNimType {.compilerproc.} =
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ proc eqStrings(a, b: NimString): bool {.inline, compilerProc.} =
|
||||||
if a == b: return true
|
if a == b: return true
|
||||||
if a == nil or b == nil: return false
|
if a == nil or b == nil: return false
|
||||||
return a.len == b.len and
|
return a.len == b.len and
|
||||||
c_memcmp(a.data, b.data, a.len * sizeof(char)) == 0'i32
|
c_memcmp(a.data, b.data, a.len) == 0'i32
|
||||||
|
|
||||||
when declared(allocAtomic):
|
when declared(allocAtomic):
|
||||||
template allocStr(size: expr): expr =
|
template allocStr(size: expr): expr =
|
||||||
|
|
@ -67,7 +67,7 @@ proc copyStrLast(s: NimString, start, last: int): NimString {.compilerProc.} =
|
||||||
if len > 0:
|
if len > 0:
|
||||||
result = rawNewStringNoInit(len)
|
result = rawNewStringNoInit(len)
|
||||||
result.len = len
|
result.len = len
|
||||||
c_memcpy(result.data, addr(s.data[start]), (len + 1) * sizeof(char))
|
c_memcpy(result.data, addr(s.data[start]), len + 1)
|
||||||
else:
|
else:
|
||||||
result = rawNewString(len)
|
result = rawNewString(len)
|
||||||
|
|
||||||
|
|
@ -77,7 +77,7 @@ proc copyStr(s: NimString, start: int): NimString {.compilerProc.} =
|
||||||
proc toNimStr(str: cstring, len: int): NimString {.compilerProc.} =
|
proc toNimStr(str: cstring, len: int): NimString {.compilerProc.} =
|
||||||
result = rawNewStringNoInit(len)
|
result = rawNewStringNoInit(len)
|
||||||
result.len = len
|
result.len = len
|
||||||
c_memcpy(result.data, str, (len+1) * sizeof(char))
|
c_memcpy(result.data, str, len + 1)
|
||||||
|
|
||||||
proc cstrToNimstr(str: cstring): NimString {.compilerRtl.} =
|
proc cstrToNimstr(str: cstring): NimString {.compilerRtl.} =
|
||||||
result = toNimStr(str, c_strlen(str))
|
result = toNimStr(str, c_strlen(str))
|
||||||
|
|
@ -89,7 +89,7 @@ proc copyString(src: NimString): NimString {.compilerRtl.} =
|
||||||
else:
|
else:
|
||||||
result = rawNewStringNoInit(src.len)
|
result = rawNewStringNoInit(src.len)
|
||||||
result.len = src.len
|
result.len = src.len
|
||||||
c_memcpy(result.data, src.data, (src.len + 1) * sizeof(char))
|
c_memcpy(result.data, src.data, src.len + 1)
|
||||||
|
|
||||||
proc copyStringRC1(src: NimString): NimString {.compilerRtl.} =
|
proc copyStringRC1(src: NimString): NimString {.compilerRtl.} =
|
||||||
if src != nil:
|
if src != nil:
|
||||||
|
|
@ -102,7 +102,7 @@ proc copyStringRC1(src: NimString): NimString {.compilerRtl.} =
|
||||||
else:
|
else:
|
||||||
result = rawNewStringNoInit(src.len)
|
result = rawNewStringNoInit(src.len)
|
||||||
result.len = src.len
|
result.len = src.len
|
||||||
c_memcpy(result.data, src.data, (src.len + 1) * sizeof(char))
|
c_memcpy(result.data, src.data, src.len + 1)
|
||||||
|
|
||||||
|
|
||||||
proc hashString(s: string): int {.compilerproc.} =
|
proc hashString(s: string): int {.compilerproc.} =
|
||||||
|
|
@ -124,7 +124,7 @@ proc addChar(s: NimString, c: char): NimString =
|
||||||
if result.len >= result.space:
|
if result.len >= result.space:
|
||||||
result.reserved = resize(result.space)
|
result.reserved = resize(result.space)
|
||||||
result = cast[NimString](growObj(result,
|
result = cast[NimString](growObj(result,
|
||||||
sizeof(TGenericSeq) + (result.reserved+1) * sizeof(char)))
|
sizeof(TGenericSeq) + result.reserved + 1))
|
||||||
result.data[result.len] = c
|
result.data[result.len] = c
|
||||||
result.data[result.len+1] = '\0'
|
result.data[result.len+1] = '\0'
|
||||||
inc(result.len)
|
inc(result.len)
|
||||||
|
|
@ -168,11 +168,11 @@ proc resizeString(dest: NimString, addlen: int): NimString {.compilerRtl.} =
|
||||||
result = cast[NimString](growObj(dest, sizeof(TGenericSeq) + sp + 1))
|
result = cast[NimString](growObj(dest, sizeof(TGenericSeq) + sp + 1))
|
||||||
result.reserved = sp
|
result.reserved = sp
|
||||||
#result = rawNewString(sp)
|
#result = rawNewString(sp)
|
||||||
#copyMem(result, dest, dest.len * sizeof(char) + sizeof(TGenericSeq))
|
#copyMem(result, dest, dest.len + sizeof(TGenericSeq))
|
||||||
# DO NOT UPDATE LEN YET: dest.len = newLen
|
# DO NOT UPDATE LEN YET: dest.len = newLen
|
||||||
|
|
||||||
proc appendString(dest, src: NimString) {.compilerproc, inline.} =
|
proc appendString(dest, src: NimString) {.compilerproc, inline.} =
|
||||||
c_memcpy(addr(dest.data[dest.len]), src.data, (src.len + 1) * sizeof(char))
|
c_memcpy(addr(dest.data[dest.len]), src.data, src.len + 1)
|
||||||
inc(dest.len, src.len)
|
inc(dest.len, src.len)
|
||||||
|
|
||||||
proc appendChar(dest: NimString, c: char) {.compilerproc, inline.} =
|
proc appendChar(dest: NimString, c: char) {.compilerproc, inline.} =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue