Permalink
Browse files

planning changes for circular optimization

  • Loading branch information...
1 parent 71af133 commit 275b952b33787e825a48fc801519eb6a3fc20a7c Peter Ohler committed Mar 4, 2012
Showing with 18 additions and 7 deletions.
  1. +4 −4 README.md
  2. +5 −2 ext/oj/load.c
  3. +9 −1 notes
View
@@ -281,11 +281,11 @@ Object being encoded. It is used when the :circular flag is set. It can appear
in either a JSON Object or in a JSON Array. In an Object the "^i" key has a
corresponding reference Fixnum. In an array the sequence will include an
embedded reference number. An example is
-{"^o":"Oj::Bag","^i":1,"x":["^i2",true],"me":{"^r":1}}.
+{"^o":"Oj::Bag","^i":1,"x":["^i2",true],"me":"^r1"}.
13. A "^r" JSON entry in an Object is a references to a Object or Array that
already appears in the JSON String. It must match up with a previous "^i"
-ID. An example is {"^o":"Oj::Bag","^i":1,"x":3,"me":{"^r":1}}.
+ID. An example is {"^o":"Oj::Bag","^i":1,"x":3,"me":"^r1"}.
-14. If an Array element is a String and starts with "^i" then it is encoded as
-an String Object. An example is [{"^s":"^i37"},3].
+14. If an Array element is a String and starts with "^i" then the first character, the ^ is encoded as a hext character.
+An example is ["\u005ei37"},3].
View
@@ -490,6 +490,7 @@ read_array(ParseInfo pi, int hint) {
int type = T_NONE;
int cnt = 0;
long slen = 0;
+ int escaped;
pi->s++;
next_non_white(pi);
@@ -498,6 +499,8 @@ read_array(ParseInfo pi, int hint) {
return rb_ary_new();
}
while (1) {
+ next_non_white(pi);
+ escaped = ('"' == *pi->s && '\\' == pi->s[1]);
if (Qundef == (e = read_next(pi, 0))) {
raise_error("unexpected character", pi->str, pi->s);
}
@@ -520,7 +523,7 @@ read_array(ParseInfo pi, int hint) {
circ_array_set(pi->circ_array, a, read_ulong(s + 2, pi));
e = Qundef;
}
- // TBD if begins with \^ then redo e one char shorter
+ // TBD if begins with \^ then redo e one char shorter, note escaped value
}
if (Qundef != e) {
if (T_STRUCT == type) {
@@ -537,7 +540,7 @@ read_array(ParseInfo pi, int hint) {
}
cnt++;
}
- next_non_white(pi); // skip white space
+ next_non_white(pi);
if (',' == *pi->s) {
pi->s++;
} else if (']' == *pi->s) {
View
10 notes
@@ -11,7 +11,15 @@
- handle array element with "^i222" that is not an id
- handle value that is "^r222" that is not a reference
- - compare
+ - use escaped to put ^ in strings instead of {"^s":"^foo"}
+ - \u005e
+ - use escaped to put : in strings instead of {"^s":":foo"}
+ - \u003a
+
+ - try simple array for dump
+ - might be faster for small numbers of circular references which is the common case
+
+ - compare circular
- yajl - core dumps ruby
- json fails
- msgpack fails

0 comments on commit 275b952

Please sign in to comment.