Skip to content

Commit

Permalink
up to 20x faster jsonutils deserialization (#18183)
Browse files Browse the repository at this point in the history
* up to 20x faster jsonutils deserialization

* noinline
  • Loading branch information
timotheecour authored Jun 5, 2021
1 parent 9c0666e commit 9c6259e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/std/jsonutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ macro initCaseObject(T: typedesc, fun: untyped): untyped =
`fun`(`key2`, typedesc[`typ`])
result.add newTree(nnkExprColonExpr, key, val)

proc checkJsonImpl(cond: bool, condStr: string, msg = "") =
if not cond:
# just pick 1 exception type for simplicity; other choices would be:
# JsonError, JsonParser, JsonKindError
raise newException(ValueError, msg)
proc raiseJsonException(condStr: string, msg: string) {.noinline.} =
# just pick 1 exception type for simplicity; other choices would be:
# JsonError, JsonParser, JsonKindError
raise newException(ValueError, condStr & " failed: " & msg)

template checkJson(cond: untyped, msg = "") =
checkJsonImpl(cond, astToStr(cond), msg)
if not cond:
raiseJsonException(astToStr(cond), msg)

proc hasField[T](obj: T, field: string): bool =
for k, _ in fieldPairs(obj):
Expand Down

0 comments on commit 9c6259e

Please sign in to comment.