optimize for the non-throwing case (#18587)
This commit is contained in:
parent
158d7c7a7a
commit
d4c3a09286
1 changed files with 7 additions and 4 deletions
|
|
@ -227,6 +227,12 @@ template dataLen(t): untyped = len(t.data)
|
||||||
|
|
||||||
include tableimpl
|
include tableimpl
|
||||||
|
|
||||||
|
proc raiseKeyError[T](key: T) {.noinline, noreturn.} =
|
||||||
|
when compiles($key):
|
||||||
|
raise newException(KeyError, "key not found: " & $key)
|
||||||
|
else:
|
||||||
|
raise newException(KeyError, "key not found")
|
||||||
|
|
||||||
template get(t, key): untyped =
|
template get(t, key): untyped =
|
||||||
## retrieves the value at `t[key]`. The value can be modified.
|
## retrieves the value at `t[key]`. The value can be modified.
|
||||||
## If `key` is not in `t`, the `KeyError` exception is raised.
|
## If `key` is not in `t`, the `KeyError` exception is raised.
|
||||||
|
|
@ -235,10 +241,7 @@ template get(t, key): untyped =
|
||||||
var index = rawGet(t, key, hc)
|
var index = rawGet(t, key, hc)
|
||||||
if index >= 0: result = t.data[index].val
|
if index >= 0: result = t.data[index].val
|
||||||
else:
|
else:
|
||||||
when compiles($key):
|
raiseKeyError(key)
|
||||||
raise newException(KeyError, "key not found: " & $key)
|
|
||||||
else:
|
|
||||||
raise newException(KeyError, "key not found")
|
|
||||||
|
|
||||||
proc enlarge[A, B](t: var Table[A, B]) =
|
proc enlarge[A, B](t: var Table[A, B]) =
|
||||||
var n: KeyValuePairSeq[A, B]
|
var n: KeyValuePairSeq[A, B]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue