diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2021-06-05 00:45:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-05 09:45:37 +0200 |
commit | 9c6259e55717acbc954140ef2bb0ca363971c8c7 (patch) | |
tree | 88f04f58092f565a411db91c4fa9b9ae0dc9758b /lib | |
parent | 9c0666e0bbb7af69e2d87e7e81302ed3d3f06412 (diff) | |
download | Nim-9c6259e55717acbc954140ef2bb0ca363971c8c7.tar.gz |
up to 20x faster jsonutils deserialization (#18183)
* up to 20x faster jsonutils deserialization * noinline
Diffstat (limited to 'lib')
-rw-r--r-- | lib/std/jsonutils.nim | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/std/jsonutils.nim b/lib/std/jsonutils.nim index 60d78fea5..c141985d3 100644 --- a/lib/std/jsonutils.nim +++ b/lib/std/jsonutils.nim @@ -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): |