Skip to content

Commit

Permalink
sets: avoid calling countBits32 for 0 (#10619)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
brentp authored and Araq committed Feb 13, 2019
1 parent 779c51c commit fe26328
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/system/sets.nim
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ proc countBits64(n: int64): int {.compilerproc.} =
result = countBits32(toU32(n and 0xffffffff'i64)) +
countBits32(toU32(n shr 32'i64))

proc cardSet(s: NimSet, len: int): int {.compilerproc.} =
result = 0
for i in countup(0, len-1):
proc cardSet(s: NimSet, len: int): int {.compilerproc, inline.} =
for i in 0..<len:
if likely(s[i] == 0): continue
inc(result, countBits32(int32(s[i])))

0 comments on commit fe26328

Please sign in to comment.