mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 09:24:36 +00:00
* fix #20997 calling system.card[T](x: set[T]) with T of int8 or uint8 uses mismatched C array sizes * fullfil set variant
29 lines
657 B
Nim
29 lines
657 B
Nim
#
|
|
#
|
|
# Nim's Runtime Library
|
|
# (c) Copyright 2012 Andreas Rumpf
|
|
#
|
|
# See the file "copying.txt", included in this
|
|
# distribution, for details about the copyright.
|
|
#
|
|
|
|
# set handling
|
|
|
|
type
|
|
NimSet = array[0..8192-1, uint8]
|
|
|
|
proc cardSetImpl(s: openArray[uint8], len: int): int {.inline.} =
|
|
var i = 0
|
|
result = 0
|
|
when defined(x86) or defined(amd64):
|
|
while i < len - 8:
|
|
inc(result, countBits64((cast[ptr uint64](s[i].unsafeAddr))[]))
|
|
inc(i, 8)
|
|
|
|
while i < len:
|
|
inc(result, countBits32(uint32(s[i])))
|
|
inc(i, 1)
|
|
|
|
proc cardSet(s: NimSet, len: int): int {.compilerproc, inline.} =
|
|
result = cardSetImpl(s, len)
|