From fe26328a196a3c426f059a36660cccf1a86928b7 Mon Sep 17 00:00:00 2001 From: Brent Pedersen Date: Sun, 10 Feb 2019 00:49:54 -0700 Subject: [PATCH] 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 --- lib/system/sets.nim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/system/sets.nim b/lib/system/sets.nim index a5f6c5de94553..91dde0b815879 100644 --- a/lib/system/sets.nim +++ b/lib/system/sets.nim @@ -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..