summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-06-05 00:45:37 -0700
committerGitHub <noreply@github.com>2021-06-05 09:45:37 +0200
commit9c6259e55717acbc954140ef2bb0ca363971c8c7 (patch)
tree88f04f58092f565a411db91c4fa9b9ae0dc9758b /lib
parent9c0666e0bbb7af69e2d87e7e81302ed3d3f06412 (diff)
downloadNim-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.nim12
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):