string is not nil anymore (#15352)

This commit is contained in:
flywind 2020-09-18 16:02:31 +08:00 • committed by GitHub
commit c57023f324
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 8 deletions

View file

@ -281,10 +281,7 @@ proc `[]=`*[T](c: var CritBitTree[T], key: string, val: T) =
template get[T](c: CritBitTree[T], key: string): T = template get[T](c: CritBitTree[T], key: string): T =
let n = rawGet(c, key) let n = rawGet(c, key)
if n == nil: if n == nil:
when compiles($key): raise newException(KeyError, "key not found: " & key)
raise newException(KeyError, "key not found: " & $key)
else:
raise newException(KeyError, "key not found")
n.val n.val

View file

@ -141,10 +141,8 @@ template get(t: StringTableRef, key: string) =
var index = rawGet(t, key) var index = rawGet(t, key)
if index >= 0: result = t.data[index].val if index >= 0: result = t.data[index].val
else: else:
when compiles($key): raise newException(KeyError, "key not found: " & key)
raise newException(KeyError, "key not found: " & $key)
else:
raise newException(KeyError, "key not found")
proc len*(t: StringTableRef): int {.rtlFunc, extern: "nst$1".} = proc len*(t: StringTableRef): int {.rtlFunc, extern: "nst$1".} =
## Returns the number of keys in `t`. ## Returns the number of keys in `t`.