stdlib: use system.default if it exists
This commit is contained in:
parent
142a2d3551
commit
aed8766e84
2 changed files with 10 additions and 12 deletions
|
|
@ -74,10 +74,11 @@ type
|
||||||
|
|
||||||
const growthFactor = 2
|
const growthFactor = 2
|
||||||
|
|
||||||
template default[T](t: typedesc[T]): T =
|
when not defined(nimHasDefault):
|
||||||
## Used by clear methods to get a default value.
|
template default[T](t: typedesc[T]): T =
|
||||||
var v: T
|
## Used by clear methods to get a default value.
|
||||||
v
|
var v: T
|
||||||
|
v
|
||||||
|
|
||||||
# hcode for real keys cannot be zero. hcode==0 signifies an empty slot. These
|
# hcode for real keys cannot be zero. hcode==0 signifies an empty slot. These
|
||||||
# two procs retain clarity of that encoding without the space cost of an enum.
|
# two procs retain clarity of that encoding without the space cost of an enum.
|
||||||
|
|
@ -162,10 +163,6 @@ template doWhile(a, b) =
|
||||||
b
|
b
|
||||||
if not a: break
|
if not a: break
|
||||||
|
|
||||||
template default[T](t: typedesc[T]): T =
|
|
||||||
var v: T
|
|
||||||
v
|
|
||||||
|
|
||||||
proc exclImpl[A](s: var HashSet[A], key: A) : bool {. inline .} =
|
proc exclImpl[A](s: var HashSet[A], key: A) : bool {. inline .} =
|
||||||
assert s.isValid, "The set needs to be initialized."
|
assert s.isValid, "The set needs to be initialized."
|
||||||
var hc: Hash
|
var hc: Hash
|
||||||
|
|
@ -492,7 +489,7 @@ proc clear*[A](s: var HashSet[A]) =
|
||||||
s.counter = 0
|
s.counter = 0
|
||||||
for i in 0..<s.data.len:
|
for i in 0..<s.data.len:
|
||||||
s.data[i].hcode = 0
|
s.data[i].hcode = 0
|
||||||
s.data[i].key = default(type(s.data[i].key))
|
s.data[i].key = default(type(s.data[i].key))
|
||||||
|
|
||||||
proc len*[A](s: HashSet[A]): int =
|
proc len*[A](s: HashSet[A]): int =
|
||||||
## Returns the number of elements in `s`.
|
## Returns the number of elements in `s`.
|
||||||
|
|
|
||||||
|
|
@ -116,9 +116,10 @@ template hasKeyOrPutImpl(enlarge) {.dirty.} =
|
||||||
maybeRehashPutImpl(enlarge)
|
maybeRehashPutImpl(enlarge)
|
||||||
else: result = true
|
else: result = true
|
||||||
|
|
||||||
template default[T](t: typedesc[T]): T =
|
when not defined(nimHasDefault):
|
||||||
var v: T
|
template default[T](t: typedesc[T]): T =
|
||||||
v
|
var v: T
|
||||||
|
v
|
||||||
|
|
||||||
template delImplIdx(t, i) =
|
template delImplIdx(t, i) =
|
||||||
let msk = maxHash(t)
|
let msk = maxHash(t)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue