stdlib: use system.default if it exists

This commit is contained in:
Andreas Rumpf
2019-03-05 10:03:24 +01:00
parent 142a2d3551
commit aed8766e84
2 changed files with 10 additions and 12 deletions

View File

@@ -74,10 +74,11 @@ type
const growthFactor = 2
template default[T](t: typedesc[T]): T =
## Used by clear methods to get a default value.
var v: T
v
when not defined(nimHasDefault):
template default[T](t: typedesc[T]): T =
## Used by clear methods to get a default value.
var v: T
v
# 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.
@@ -162,10 +163,6 @@ template doWhile(a, b) =
b
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 .} =
assert s.isValid, "The set needs to be initialized."
var hc: Hash
@@ -492,7 +489,7 @@ proc clear*[A](s: var HashSet[A]) =
s.counter = 0
for i in 0..<s.data.len:
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 =
## Returns the number of elements in `s`.

View File

@@ -116,9 +116,10 @@ template hasKeyOrPutImpl(enlarge) {.dirty.} =
maybeRehashPutImpl(enlarge)
else: result = true
template default[T](t: typedesc[T]): T =
var v: T
v
when not defined(nimHasDefault):
template default[T](t: typedesc[T]): T =
var v: T
v
template delImplIdx(t, i) =
let msk = maxHash(t)