up to 20x faster jsonutils deserialization (#18183)
* up to 20x faster jsonutils deserialization * noinline
This commit is contained in:
parent
9c0666e0bb
commit
9c6259e557
1 changed files with 6 additions and 6 deletions
|
|
@ -128,14 +128,14 @@ macro initCaseObject(T: typedesc, fun: untyped): untyped =
|
||||||
`fun`(`key2`, typedesc[`typ`])
|
`fun`(`key2`, typedesc[`typ`])
|
||||||
result.add newTree(nnkExprColonExpr, key, val)
|
result.add newTree(nnkExprColonExpr, key, val)
|
||||||
|
|
||||||
proc checkJsonImpl(cond: bool, condStr: string, msg = "") =
|
proc raiseJsonException(condStr: string, msg: string) {.noinline.} =
|
||||||
if not cond:
|
# just pick 1 exception type for simplicity; other choices would be:
|
||||||
# just pick 1 exception type for simplicity; other choices would be:
|
# JsonError, JsonParser, JsonKindError
|
||||||
# JsonError, JsonParser, JsonKindError
|
raise newException(ValueError, condStr & " failed: " & msg)
|
||||||
raise newException(ValueError, msg)
|
|
||||||
|
|
||||||
template checkJson(cond: untyped, 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 =
|
proc hasField[T](obj: T, field: string): bool =
|
||||||
for k, _ in fieldPairs(obj):
|
for k, _ in fieldPairs(obj):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue