mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-23 19:36:53 +00:00
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:
committed by
Andreas Rumpf
parent
779c51c29b
commit
fe26328a19
@@ -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])))
|
||||
|
||||
Reference in New Issue
Block a user