oj 3.7.4 → 3.13.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1352 -0
  3. data/README.md +29 -8
  4. data/RELEASE_NOTES.md +61 -0
  5. data/ext/oj/buf.h +53 -72
  6. data/ext/oj/cache.c +326 -0
  7. data/ext/oj/cache.h +21 -0
  8. data/ext/oj/cache8.c +61 -64
  9. data/ext/oj/cache8.h +12 -39
  10. data/ext/oj/circarray.c +37 -43
  11. data/ext/oj/circarray.h +16 -17
  12. data/ext/oj/code.c +165 -179
  13. data/ext/oj/code.h +27 -29
  14. data/ext/oj/compat.c +174 -194
  15. data/ext/oj/custom.c +809 -866
  16. data/ext/oj/debug.c +132 -0
  17. data/ext/oj/dump.c +848 -863
  18. data/ext/oj/dump.h +81 -67
  19. data/ext/oj/dump_compat.c +85 -123
  20. data/ext/oj/dump_leaf.c +100 -188
  21. data/ext/oj/dump_object.c +527 -656
  22. data/ext/oj/dump_strict.c +315 -338
  23. data/ext/oj/encode.h +7 -34
  24. data/ext/oj/encoder.c +43 -0
  25. data/ext/oj/err.c +40 -29
  26. data/ext/oj/err.h +48 -48
  27. data/ext/oj/extconf.rb +17 -4
  28. data/ext/oj/fast.c +1070 -1087
  29. data/ext/oj/intern.c +301 -0
  30. data/ext/oj/intern.h +26 -0
  31. data/ext/oj/mimic_json.c +469 -436
  32. data/ext/oj/object.c +525 -593
  33. data/ext/oj/odd.c +154 -138
  34. data/ext/oj/odd.h +37 -38
  35. data/ext/oj/oj.c +1325 -986
  36. data/ext/oj/oj.h +333 -316
  37. data/ext/oj/parse.c +1002 -846
  38. data/ext/oj/parse.h +92 -87
  39. data/ext/oj/parser.c +1557 -0
  40. data/ext/oj/parser.h +91 -0
  41. data/ext/oj/rails.c +888 -878
  42. data/ext/oj/rails.h +11 -14
  43. data/ext/oj/reader.c +141 -147
  44. data/ext/oj/reader.h +73 -89
  45. data/ext/oj/resolve.c +41 -62
  46. data/ext/oj/resolve.h +7 -9
  47. data/ext/oj/rxclass.c +71 -75
  48. data/ext/oj/rxclass.h +18 -19
  49. data/ext/oj/saj.c +443 -486
  50. data/ext/oj/saj2.c +602 -0
  51. data/ext/oj/scp.c +88 -113
  52. data/ext/oj/sparse.c +787 -709
  53. data/ext/oj/stream_writer.c +133 -159
  54. data/ext/oj/strict.c +127 -118
  55. data/ext/oj/string_writer.c +230 -249
  56. data/ext/oj/trace.c +34 -41
  57. data/ext/oj/trace.h +19 -19
  58. data/ext/oj/usual.c +1254 -0
  59. data/ext/oj/util.c +136 -0
  60. data/ext/oj/util.h +20 -0
  61. data/ext/oj/val_stack.c +59 -67
  62. data/ext/oj/val_stack.h +91 -129
  63. data/ext/oj/validate.c +46 -0
  64. data/ext/oj/wab.c +342 -353
  65. data/lib/oj/bag.rb +1 -0
  66. data/lib/oj/easy_hash.rb +5 -4
  67. data/lib/oj/error.rb +1 -1
  68. data/lib/oj/json.rb +1 -1
  69. data/lib/oj/mimic.rb +48 -14
  70. data/lib/oj/saj.rb +20 -6
  71. data/lib/oj/state.rb +8 -7
  72. data/lib/oj/version.rb +2 -2
  73. data/lib/oj.rb +0 -8
  74. data/pages/Compatibility.md +1 -1
  75. data/pages/JsonGem.md +15 -0
  76. data/pages/Modes.md +53 -46
  77. data/pages/Options.md +72 -11
  78. data/pages/Parser.md +309 -0
  79. data/pages/Rails.md +73 -22
  80. data/pages/Security.md +1 -1
  81. data/test/activerecord/result_test.rb +7 -2
  82. data/test/activesupport5/abstract_unit.rb +45 -0
  83. data/test/activesupport5/decoding_test.rb +68 -60
  84. data/test/activesupport5/encoding_test.rb +111 -96
  85. data/test/activesupport5/encoding_test_cases.rb +33 -25
  86. data/test/activesupport5/test_helper.rb +43 -21
  87. data/test/activesupport5/time_zone_test_helpers.rb +18 -3
  88. data/test/activesupport6/abstract_unit.rb +44 -0
  89. data/test/activesupport6/decoding_test.rb +133 -0
  90. data/test/activesupport6/encoding_test.rb +507 -0
  91. data/test/activesupport6/encoding_test_cases.rb +98 -0
  92. data/test/activesupport6/test_common.rb +17 -0
  93. data/test/activesupport6/test_helper.rb +163 -0
  94. data/test/activesupport6/time_zone_test_helpers.rb +39 -0
  95. data/test/activesupport7/abstract_unit.rb +49 -0
  96. data/test/activesupport7/decoding_test.rb +125 -0
  97. data/test/activesupport7/encoding_test.rb +486 -0
  98. data/test/activesupport7/encoding_test_cases.rb +104 -0
  99. data/test/activesupport7/time_zone_test_helpers.rb +47 -0
  100. data/test/bar.rb +6 -12
  101. data/test/baz.rb +16 -0
  102. data/test/bug.rb +16 -0
  103. data/test/foo.rb +69 -75
  104. data/test/helper.rb +16 -0
  105. data/test/json_gem/json_common_interface_test.rb +8 -3
  106. data/test/json_gem/json_generator_test.rb +18 -4
  107. data/test/json_gem/json_parser_test.rb +9 -0
  108. data/test/json_gem/test_helper.rb +12 -0
  109. data/test/mem.rb +33 -0
  110. data/test/perf.rb +1 -1
  111. data/test/perf_dump.rb +50 -0
  112. data/test/perf_once.rb +58 -0
  113. data/test/perf_parser.rb +189 -0
  114. data/test/perf_scp.rb +11 -10
  115. data/test/perf_strict.rb +17 -23
  116. data/test/prec.rb +23 -0
  117. data/test/sample_json.rb +1 -1
  118. data/test/test_compat.rb +46 -10
  119. data/test/test_custom.rb +147 -8
  120. data/test/test_fast.rb +62 -2
  121. data/test/test_file.rb +25 -2
  122. data/test/test_gc.rb +13 -0
  123. data/test/test_generate.rb +21 -0
  124. data/test/test_hash.rb +11 -1
  125. data/test/test_integer_range.rb +7 -2
  126. data/test/test_object.rb +85 -9
  127. data/test/test_parser.rb +27 -0
  128. data/test/test_parser_saj.rb +335 -0
  129. data/test/test_parser_usual.rb +217 -0
  130. data/test/test_rails.rb +35 -0
  131. data/test/test_saj.rb +1 -1
  132. data/test/test_scp.rb +5 -5
  133. data/test/test_strict.rb +26 -1
  134. data/test/test_various.rb +87 -65
  135. data/test/test_wab.rb +2 -0
  136. data/test/test_writer.rb +19 -2
  137. data/test/tests.rb +1 -1
  138. data/test/zoo.rb +13 -0
  139. metadata +60 -110
  140. data/ext/oj/hash.c +0 -163
  141. data/ext/oj/hash.h +0 -46
  142. data/ext/oj/hash_test.c +0 -512
data/ext/oj/compat.c CHANGED
@@ -1,298 +1,278 @@
1
- /* compat.c
2
- * Copyright (c) 2012, Peter Ohler
3
- * All rights reserved.
4
- */
1
+ // Copyright (c) 2012 Peter Ohler. All rights reserved.
2
+ // Licensed under the MIT License. See LICENSE file in the project root for license details.
5
3
 
6
4
  #include <stdio.h>
7
5
 
8
- #include "oj.h"
6
+ #include "encode.h"
9
7
  #include "err.h"
8
+ #include "intern.h"
9
+ #include "oj.h"
10
10
  #include "parse.h"
11
11
  #include "resolve.h"
12
- #include "hash.h"
13
- #include "encode.h"
14
12
  #include "trace.h"
15
13
 
16
- static void
17
- hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
18
- const char *key = kval->key;
19
- int klen = kval->klen;
20
- Val parent = stack_peek(&pi->stack);
21
- volatile VALUE rkey = kval->key_val;
22
-
23
- if (Qundef == rkey &&
24
- Yes == pi->options.create_ok &&
25
- NULL != pi->options.create_id &&
26
- *pi->options.create_id == *key &&
27
- (int)pi->options.create_id_len == klen &&
28
- 0 == strncmp(pi->options.create_id, key, klen)) {
29
-
30
- parent->classname = oj_strndup(str, len);
31
- parent->clen = len;
14
+ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
15
+ const char * key = kval->key;
16
+ int klen = kval->klen;
17
+ Val parent = stack_peek(&pi->stack);
18
+ volatile VALUE rkey = kval->key_val;
19
+
20
+ if (Qundef == rkey && Yes == pi->options.create_ok && NULL != pi->options.create_id &&
21
+ *pi->options.create_id == *key && (int)pi->options.create_id_len == klen &&
22
+ 0 == strncmp(pi->options.create_id, key, klen)) {
23
+ parent->classname = oj_strndup(str, len);
24
+ parent->clen = len;
32
25
  } else {
33
- volatile VALUE rstr = rb_str_new(str, len);
34
-
35
- if (Qundef == rkey) {
36
- rkey = rb_str_new(key, klen);
37
- rstr = oj_encode(rstr);
38
- rkey = oj_encode(rkey);
39
- if (Yes == pi->options.sym_key) {
40
- rkey = rb_str_intern(rkey);
41
- }
42
- }
43
- if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
44
- VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
45
-
46
- if (Qnil != clas) {
47
- rstr = rb_funcall(clas, oj_json_create_id, 1, rstr);
48
- }
49
- }
50
- if (rb_cHash != rb_obj_class(parent->val)) {
51
- // The rb_hash_set would still work but the unit tests for the
52
- // json gem require the less efficient []= method be called to set
53
- // values. Even using the store method to set the values will fail
54
- // the unit tests.
55
- rb_funcall(parent->val, rb_intern("[]="), 2, rkey, rstr);
56
- } else {
57
- rb_hash_aset(parent->val, rkey, rstr);
58
- }
59
- if (Yes == pi->options.trace) {
60
- oj_trace_parse_call("set_string", pi, __FILE__, __LINE__, rstr);
61
- }
26
+ volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
27
+
28
+ if (Qundef == rkey) {
29
+ if (Yes != pi->options.cache_keys) {
30
+ if (Yes == pi->options.sym_key) {
31
+ rkey = ID2SYM(rb_intern3(key, klen, oj_utf8_encoding));
32
+ } else {
33
+ rkey = rb_utf8_str_new(key, klen);
34
+ }
35
+ } else if (Yes == pi->options.sym_key) {
36
+ rkey = oj_sym_intern(key, klen);
37
+ } else {
38
+ rkey = oj_str_intern(key, klen);
39
+ }
40
+ }
41
+ if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
42
+ VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
43
+
44
+ if (Qnil != clas) {
45
+ rstr = rb_funcall(clas, oj_json_create_id, 1, rstr);
46
+ }
47
+ }
48
+ if (rb_cHash != rb_obj_class(parent->val)) {
49
+ // The rb_hash_set would still work but the unit tests for the
50
+ // json gem require the less efficient []= method be called to set
51
+ // values. Even using the store method to set the values will fail
52
+ // the unit tests.
53
+ rb_funcall(parent->val, rb_intern("[]="), 2, rkey, rstr);
54
+ } else {
55
+ rb_hash_aset(parent->val, rkey, rstr);
56
+ }
57
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
58
+ oj_trace_parse_call("set_string", pi, __FILE__, __LINE__, rstr);
59
+ }
62
60
  }
63
61
  }
64
62
 
65
- static VALUE
66
- start_hash(ParseInfo pi) {
67
- volatile VALUE h;
68
-
63
+ static VALUE start_hash(ParseInfo pi) {
64
+ volatile VALUE h;
65
+
69
66
  if (Qnil != pi->options.hash_class) {
70
- h = rb_class_new_instance(0, NULL, pi->options.hash_class);
67
+ h = rb_class_new_instance(0, NULL, pi->options.hash_class);
71
68
  } else {
72
- h = rb_hash_new();
69
+ h = rb_hash_new();
73
70
  }
74
- if (Yes == pi->options.trace) {
75
- oj_trace_parse_in("start_hash", pi, __FILE__, __LINE__);
71
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
72
+ oj_trace_parse_in("start_hash", pi, __FILE__, __LINE__);
76
73
  }
77
74
  return h;
78
75
  }
79
76
 
80
- static void
81
- end_hash(struct _ParseInfo *pi) {
82
- Val parent = stack_peek(&pi->stack);
77
+ static void end_hash(struct _parseInfo *pi) {
78
+ Val parent = stack_peek(&pi->stack);
83
79
 
84
80
  if (0 != parent->classname) {
85
- volatile VALUE clas;
86
-
87
- clas = oj_name2class(pi, parent->classname, parent->clen, 0, rb_eArgError);
88
- if (Qundef != clas) { // else an error
89
- ID creatable = rb_intern("json_creatable?");
90
-
91
- if (!rb_respond_to(clas, creatable) || Qtrue == rb_funcall(clas, creatable, 0)) {
92
- parent->val = rb_funcall(clas, oj_json_create_id, 1, parent->val);
93
- }
94
- }
95
- if (0 != parent->classname) {
96
- xfree((char*)parent->classname);
97
- parent->classname = 0;
98
- }
81
+ volatile VALUE clas;
82
+
83
+ clas = oj_name2class(pi, parent->classname, parent->clen, 0, rb_eArgError);
84
+ if (Qundef != clas) { // else an error
85
+ ID creatable = rb_intern("json_creatable?");
86
+
87
+ if (!rb_respond_to(clas, creatable) || Qtrue == rb_funcall(clas, creatable, 0)) {
88
+ parent->val = rb_funcall(clas, oj_json_create_id, 1, parent->val);
89
+ }
90
+ }
91
+ if (0 != parent->classname) {
92
+ xfree((char *)parent->classname);
93
+ parent->classname = 0;
94
+ }
99
95
  }
100
- if (Yes == pi->options.trace) {
101
- oj_trace_parse_hash_end(pi, __FILE__, __LINE__);
96
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
97
+ oj_trace_parse_hash_end(pi, __FILE__, __LINE__);
102
98
  }
103
99
  }
104
100
 
105
- static VALUE
106
- calc_hash_key(ParseInfo pi, Val parent) {
107
- volatile VALUE rkey = parent->key_val;
101
+ static void add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
102
+ volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
108
103
 
109
- if (Qundef == rkey) {
110
- rkey = rb_str_new(parent->key, parent->klen);
111
- }
112
- rkey = oj_encode(rkey);
113
- if (Yes == pi->options.sym_key) {
114
- rkey = rb_str_intern(rkey);
115
- }
116
- return rkey;
117
- }
118
-
119
- static void
120
- add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
121
- volatile VALUE rstr = rb_str_new(str, len);
122
-
123
- rstr = oj_encode(rstr);
124
104
  if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
125
- VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
105
+ VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
126
106
 
127
- if (Qnil != clas) {
128
- pi->stack.head->val = rb_funcall(clas, oj_json_create_id, 1, rstr);
129
- return;
130
- }
107
+ if (Qnil != clas) {
108
+ pi->stack.head->val = rb_funcall(clas, oj_json_create_id, 1, rstr);
109
+ return;
110
+ }
131
111
  }
132
112
  pi->stack.head->val = rstr;
133
- if (Yes == pi->options.trace) {
134
- oj_trace_parse_call("add_string", pi, __FILE__, __LINE__, rstr);
113
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
114
+ oj_trace_parse_call("add_string", pi, __FILE__, __LINE__, rstr);
135
115
  }
136
116
  }
137
117
 
138
- static void
139
- add_num(ParseInfo pi, NumInfo ni) {
118
+ static void add_num(ParseInfo pi, NumInfo ni) {
140
119
  pi->stack.head->val = oj_num_as_value(ni);
141
- if (Yes == pi->options.trace) {
142
- oj_trace_parse_call("add_number", pi, __FILE__, __LINE__, pi->stack.head->val);
120
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
121
+ oj_trace_parse_call("add_number", pi, __FILE__, __LINE__, pi->stack.head->val);
143
122
  }
144
123
  }
145
124
 
146
- static void
147
- hash_set_num(struct _ParseInfo *pi, Val parent, NumInfo ni) {
148
- volatile VALUE rval = oj_num_as_value(ni);
149
-
125
+ static void hash_set_num(struct _parseInfo *pi, Val parent, NumInfo ni) {
126
+ volatile VALUE rval = oj_num_as_value(ni);
127
+
150
128
  if (!oj_use_hash_alt && rb_cHash != rb_obj_class(parent->val)) {
151
- // The rb_hash_set would still work but the unit tests for the
152
- // json gem require the less efficient []= method be called to set
153
- // values. Even using the store method to set the values will fail
154
- // the unit tests.
155
- rb_funcall(stack_peek(&pi->stack)->val, rb_intern("[]="), 2, calc_hash_key(pi, parent), rval);
129
+ // The rb_hash_set would still work but the unit tests for the
130
+ // json gem require the less efficient []= method be called to set
131
+ // values. Even using the store method to set the values will fail
132
+ // the unit tests.
133
+ rb_funcall(stack_peek(&pi->stack)->val,
134
+ rb_intern("[]="),
135
+ 2,
136
+ oj_calc_hash_key(pi, parent),
137
+ rval);
156
138
  } else {
157
- rb_hash_aset(stack_peek(&pi->stack)->val, calc_hash_key(pi, parent), rval);
139
+ rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), rval);
158
140
  }
159
- if (Yes == pi->options.trace) {
160
- oj_trace_parse_call("set_number", pi, __FILE__, __LINE__, rval);
141
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
142
+ oj_trace_parse_call("set_number", pi, __FILE__, __LINE__, rval);
161
143
  }
162
144
  }
163
145
 
164
- static void
165
- hash_set_value(ParseInfo pi, Val parent, VALUE value) {
146
+ static void hash_set_value(ParseInfo pi, Val parent, VALUE value) {
166
147
  if (rb_cHash != rb_obj_class(parent->val)) {
167
- // The rb_hash_set would still work but the unit tests for the
168
- // json gem require the less efficient []= method be called to set
169
- // values. Even using the store method to set the values will fail
170
- // the unit tests.
171
- rb_funcall(stack_peek(&pi->stack)->val, rb_intern("[]="), 2, calc_hash_key(pi, parent), value);
148
+ // The rb_hash_set would still work but the unit tests for the
149
+ // json gem require the less efficient []= method be called to set
150
+ // values. Even using the store method to set the values will fail
151
+ // the unit tests.
152
+ rb_funcall(stack_peek(&pi->stack)->val,
153
+ rb_intern("[]="),
154
+ 2,
155
+ oj_calc_hash_key(pi, parent),
156
+ value);
172
157
  } else {
173
- rb_hash_aset(stack_peek(&pi->stack)->val, calc_hash_key(pi, parent), value);
158
+ rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), value);
174
159
  }
175
- if (Yes == pi->options.trace) {
176
- oj_trace_parse_call("set_value", pi, __FILE__, __LINE__, value);
160
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
161
+ oj_trace_parse_call("set_value", pi, __FILE__, __LINE__, value);
177
162
  }
178
163
  }
179
164
 
180
- static VALUE
181
- start_array(ParseInfo pi) {
165
+ static VALUE start_array(ParseInfo pi) {
182
166
  if (Qnil != pi->options.array_class) {
183
- return rb_class_new_instance(0, NULL, pi->options.array_class);
167
+ return rb_class_new_instance(0, NULL, pi->options.array_class);
184
168
  }
185
- if (Yes == pi->options.trace) {
186
- oj_trace_parse_in("start_array", pi, __FILE__, __LINE__);
169
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
170
+ oj_trace_parse_in("start_array", pi, __FILE__, __LINE__);
187
171
  }
188
172
  return rb_ary_new();
189
173
  }
190
174
 
191
- static void
192
- array_append_num(ParseInfo pi, NumInfo ni) {
193
- Val parent = stack_peek(&pi->stack);
194
- volatile VALUE rval = oj_num_as_value(ni);
195
-
175
+ static void array_append_num(ParseInfo pi, NumInfo ni) {
176
+ Val parent = stack_peek(&pi->stack);
177
+ volatile VALUE rval = oj_num_as_value(ni);
178
+
196
179
  if (!oj_use_array_alt && rb_cArray != rb_obj_class(parent->val)) {
197
- // The rb_ary_push would still work but the unit tests for the json
198
- // gem require the less efficient << method be called to push the
199
- // values.
200
- rb_funcall(parent->val, rb_intern("<<"), 1, rval);
180
+ // The rb_ary_push would still work but the unit tests for the json
181
+ // gem require the less efficient << method be called to push the
182
+ // values.
183
+ rb_funcall(parent->val, rb_intern("<<"), 1, rval);
201
184
  } else {
202
- rb_ary_push(parent->val, rval);
185
+ rb_ary_push(parent->val, rval);
203
186
  }
204
- if (Yes == pi->options.trace) {
205
- oj_trace_parse_call("append_number", pi, __FILE__, __LINE__, rval);
187
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
188
+ oj_trace_parse_call("append_number", pi, __FILE__, __LINE__, rval);
206
189
  }
207
190
  }
208
191
 
209
- static void
210
- array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
211
- volatile VALUE rstr = rb_str_new(str, len);
192
+ static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
193
+ volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
212
194
 
213
- rstr = oj_encode(rstr);
214
195
  if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
215
- VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
196
+ VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
216
197
 
217
- if (Qnil != clas) {
218
- rb_ary_push(stack_peek(&pi->stack)->val, rb_funcall(clas, oj_json_create_id, 1, rstr));
219
- return;
220
- }
198
+ if (Qnil != clas) {
199
+ rb_ary_push(stack_peek(&pi->stack)->val, rb_funcall(clas, oj_json_create_id, 1, rstr));
200
+ return;
201
+ }
221
202
  }
222
203
  rb_ary_push(stack_peek(&pi->stack)->val, rstr);
223
- if (Yes == pi->options.trace) {
224
- oj_trace_parse_call("append_string", pi, __FILE__, __LINE__, rstr);
204
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
205
+ oj_trace_parse_call("append_string", pi, __FILE__, __LINE__, rstr);
225
206
  }
226
207
  }
227
208
 
228
- void
229
- oj_set_compat_callbacks(ParseInfo pi) {
209
+ void oj_set_compat_callbacks(ParseInfo pi) {
230
210
  oj_set_strict_callbacks(pi);
231
- pi->start_hash = start_hash;
232
- pi->end_hash = end_hash;
233
- pi->hash_set_cstr = hash_set_cstr;
234
- pi->hash_set_num = hash_set_num;
235
- pi->hash_set_value = hash_set_value;
236
- pi->add_num = add_num;
237
- pi->add_cstr = add_cstr;
211
+ pi->start_hash = start_hash;
212
+ pi->end_hash = end_hash;
213
+ pi->hash_set_cstr = hash_set_cstr;
214
+ pi->hash_set_num = hash_set_num;
215
+ pi->hash_set_value = hash_set_value;
216
+ pi->add_num = add_num;
217
+ pi->add_cstr = add_cstr;
238
218
  pi->array_append_cstr = array_append_cstr;
239
- pi->start_array = start_array;
240
- pi->array_append_num = array_append_num;
219
+ pi->start_array = start_array;
220
+ pi->array_append_num = array_append_num;
241
221
  }
242
222
 
243
223
  VALUE
244
224
  oj_compat_parse(int argc, VALUE *argv, VALUE self) {
245
- struct _ParseInfo pi;
225
+ struct _parseInfo pi;
246
226
 
247
227
  parse_info_init(&pi);
248
- pi.options = oj_default_options;
249
- pi.handler = Qnil;
250
- pi.err_class = Qnil;
251
- pi.max_depth = 0;
252
- pi.options.allow_nan = Yes;
253
- pi.options.nilnil = Yes;
228
+ pi.options = oj_default_options;
229
+ pi.handler = Qnil;
230
+ pi.err_class = Qnil;
231
+ pi.max_depth = 0;
232
+ pi.options.allow_nan = Yes;
233
+ pi.options.nilnil = Yes;
254
234
  pi.options.empty_string = No;
255
235
  oj_set_compat_callbacks(&pi);
256
236
 
257
237
  if (T_STRING == rb_type(*argv)) {
258
- return oj_pi_parse(argc, argv, &pi, 0, 0, false);
238
+ return oj_pi_parse(argc, argv, &pi, 0, 0, false);
259
239
  } else {
260
- return oj_pi_sparse(argc, argv, &pi, 0);
240
+ return oj_pi_sparse(argc, argv, &pi, 0);
261
241
  }
262
242
  }
263
243
 
264
244
  VALUE
265
245
  oj_compat_load(int argc, VALUE *argv, VALUE self) {
266
- struct _ParseInfo pi;
246
+ struct _parseInfo pi;
267
247
 
268
248
  parse_info_init(&pi);
269
- pi.options = oj_default_options;
270
- pi.handler = Qnil;
271
- pi.err_class = Qnil;
272
- pi.max_depth = 0;
273
- pi.options.allow_nan = Yes;
274
- pi.options.nilnil = Yes;
249
+ pi.options = oj_default_options;
250
+ pi.handler = Qnil;
251
+ pi.err_class = Qnil;
252
+ pi.max_depth = 0;
253
+ pi.options.allow_nan = Yes;
254
+ pi.options.nilnil = Yes;
275
255
  pi.options.empty_string = Yes;
276
256
  oj_set_compat_callbacks(&pi);
277
-
257
+
278
258
  if (T_STRING == rb_type(*argv)) {
279
- return oj_pi_parse(argc, argv, &pi, 0, 0, false);
259
+ return oj_pi_parse(argc, argv, &pi, 0, 0, false);
280
260
  } else {
281
- return oj_pi_sparse(argc, argv, &pi, 0);
261
+ return oj_pi_sparse(argc, argv, &pi, 0);
282
262
  }
283
263
  }
284
264
 
285
265
  VALUE
286
266
  oj_compat_parse_cstr(int argc, VALUE *argv, char *json, size_t len) {
287
- struct _ParseInfo pi;
267
+ struct _parseInfo pi;
288
268
 
289
269
  parse_info_init(&pi);
290
- pi.options = oj_default_options;
291
- pi.handler = Qnil;
292
- pi.err_class = Qnil;
293
- pi.max_depth = 0;
270
+ pi.options = oj_default_options;
271
+ pi.handler = Qnil;
272
+ pi.err_class = Qnil;
273
+ pi.max_depth = 0;
294
274
  pi.options.allow_nan = Yes;
295
- pi.options.nilnil = Yes;
275
+ pi.options.nilnil = Yes;
296
276
  oj_set_compat_callbacks(&pi);
297
277
 
298
278
  return oj_pi_parse(argc, argv, &pi, json, len, false);