C code gen: generate even better code for the GC

This commit is contained in:
Araq 2011-12-12 22:46:21 +01:00
commit e8376067ef
4 changed files with 41 additions and 15 deletions

View file

@ -72,6 +72,20 @@ proc copyString(src: NimString): NimString {.compilerProc.} =
result.len = src.len
c_memcpy(result.data, src.data, (src.len + 1) * sizeof(Char))
proc copyStringRC1(src: NimString): NimString {.compilerProc.} =
if src != nil:
var s = src.space
if s < 8: s = 7
when defined(newObjRC1):
result = cast[NimString](newObjRC1(addr(strDesc), sizeof(TGenericSeq) +
(s+1) * sizeof(char)))
else:
result = cast[NimString](newObj(addr(strDesc), sizeof(TGenericSeq) +
(s+1) * sizeof(char)))
result.space = s
result.len = src.len
c_memcpy(result.data, src.data, (src.len + 1) * sizeof(Char))
proc hashString(s: string): int {.compilerproc.} =
# the compiler needs exactly the same hash function!
# this used to be used for efficient generation of string case statements