mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-03 19:52:36 +00:00
up to 20x faster jsonutils deserialization (#18183)
* up to 20x faster jsonutils deserialization * noinline
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user