diff --git a/Serializing/JSONVisitor.h b/Serializing/JSONVisitor.h index 528f65c..76e2b30 100644 --- a/Serializing/JSONVisitor.h +++ b/Serializing/JSONVisitor.h @@ -134,6 +134,36 @@ //printf("exit deserializing for -%s-, got -%s-\n", name, str.c_str()); } + // Idea here is try to do things on the stack to reduce heap allocations / array resizing + template + void VisitArrayRecurse(Array& arr, int depth = 0) + { + if (depth = 0) + { + String str; + ParseString(str); // gets the '[' + assert(str == "["); + } + + T item; + Visit(item); + + String str; + ParseString(str); // gets the ',' or ']' or '],' + if (str != ",") + { + //printf("expecting ]"); + //printf("str: -%s-", str.c_str()); + assert(str == "]"); + arr.resize(depth + 1); + arr[depth] = item; + return; + } + + VisitArrayRecurse(arr, depth + 1); + arr[depth] = item; + } + template void Visit(Array& arr) {