sets: avoid calling countBits32 for 0 (#10619)

this speeds up the system.sets time from ~0.2 to ~0.06
in release mode. This is still slower than intsets and
tables (which both are ~0.01).

This assumes that most sets will be sparse.

fixes #10617
This commit is contained in:
Brent Pedersen 2019-02-10 00:49:54 -07:00 • committed by Andreas Rumpf
commit 0c9a3d4804

View file

@ -22,7 +22,7 @@ proc countBits64(n: int64): int {.compilerproc.} =
result = countBits32(toU32(n and 0xffffffff'i64)) + result = countBits32(toU32(n and 0xffffffff'i64)) +
countBits32(toU32(n shr 32'i64)) countBits32(toU32(n shr 32'i64))
proc cardSet(s: NimSet, len: int): int {.compilerproc.} = proc cardSet(s: NimSet, len: int): int {.compilerproc, inline.} =
result = 0 for i in 0..<len:
for i in countup(0, len-1): if likely(s[i] == 0): continue
inc(result, countBits32(int32(s[i]))) inc(result, countBits32(int32(s[i])))