Skip to content

Commit

Permalink
try to make it bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
narimiran committed May 12, 2019
1 parent 8c4ecc1 commit 28b9097
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/pure/hashes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ proc hash*[T: Ordinal](x: T): Hash {.inline.} =
## Efficient hashing of other ordinal types (e.g. enums).
result = ord(x)

template singleByteHashImpl(result: Hash, x: typed, start, stop: int) =
proc singleByteHashImpl[T](h: var Hash, x: openArray[T], start, stop: int) {.inline.} =
for i in start .. stop:
result = result !& hash(x[i])
h = h !& hash(x[i])

template multiByteHashImpl(result: Hash, x: typed, start, stop: int) =
let stepSize = IntSize div sizeof(x[start])
Expand Down Expand Up @@ -179,12 +179,21 @@ proc hash*(x: cstring): Hash =
doAssert hash(cstring"abracadabra") != hash(cstring"AbracadabrA")

when nimvm:
var i = 0
while x[i] != '\0':
var j = 0
while x[j] != '\0':
result = result !& ord(x[j])
inc j
else:
var
i = 0
l = len(x)
while i < l - IntSize:
let n = cast[ptr Hash](unsafeAddr x[i])[]
result = result !& n
i += IntSize
while i < l:
result = result !& ord(x[i])
inc i
else:
multiByteHashImpl(result, x, 0, high(x))
result = !$result

proc hash*(sBuf: string, sPos, ePos: int): Hash =
Expand Down

0 comments on commit 28b9097

Please sign in to comment.