summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authordef <dennis@felsin9.de>2016-02-02 12:47:40 +0100
committerdef <dennis@felsin9.de>2016-02-24 19:03:55 +0100
commit9aecdb587bdc8d392d37cc12268e42456daf50d5 (patch)
tree5c214516aa8a3a4120f18bccec64c7fce917b9fa /lib
parent57897698d18bf56808409c7d52efa394a01bf549 (diff)
downloadNim-9aecdb587bdc8d392d37cc12268e42456daf50d5.tar.gz
Initialize JObject fields with capacity 4 by default to save memory and improve performance
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/json.nim6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/pure/json.nim b/lib/pure/json.nim
index 61b061b7f..b53bc3f02 100644
--- a/lib/pure/json.nim
+++ b/lib/pure/json.nim
@@ -617,7 +617,7 @@ proc newJObject*(): JsonNode =
   ## Creates a new `JObject JsonNode`
   new(result)
   result.kind = JObject
-  result.fields = initTable[string, JsonNode]()
+  result.fields = initTable[string, JsonNode](4)
 
 proc newJArray*(): JsonNode =
   ## Creates a new `JArray JsonNode`
@@ -657,7 +657,7 @@ proc getBVal*(n: JsonNode, default: bool = false): bool =
   else: return n.bval
 
 proc getFields*(n: JsonNode,
-    default = initTable[string, JsonNode]()):
+    default = initTable[string, JsonNode](4)):
         Table[string, JsonNode] =
   ## Retrieves the key, value pairs of a `JObject JsonNode`.
   ##
@@ -700,7 +700,7 @@ proc `%`*(keyVals: openArray[tuple[key: string, val: JsonNode]]): JsonNode =
   ## Generic constructor for JSON data. Creates a new `JObject JsonNode`
   new(result)
   result.kind = JObject
-  result.fields = initTable[string, JsonNode]()
+  result.fields = initTable[string, JsonNode](4)
   for key, val in items(keyVals): result.fields[key] = val
 
 proc `%`*(elements: openArray[JsonNode]): JsonNode =