Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

up to 20x faster jsonutils deserialization #18183

Merged
merged 2 commits into from
Jun 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
ringabout marked this conversation as resolved.
Show resolved Hide resolved
raiseJsonException(astToStr(cond), msg)

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