oj 3.13.14 → 3.13.17

Sign up to get free protection for your applications and to get access to all the features.
data/ext/oj/saj2.c CHANGED
@@ -6,8 +6,8 @@
6
6
 
7
7
  typedef struct _delegate {
8
8
  VALUE handler;
9
- VALUE * keys;
10
- VALUE * tail;
9
+ VALUE *keys;
10
+ VALUE *tail;
11
11
  size_t klen;
12
12
  struct _cache *str_cache;
13
13
  uint8_t cache_str;
@@ -17,7 +17,7 @@ typedef struct _delegate {
17
17
 
18
18
  static VALUE get_key(ojParser p) {
19
19
  Delegate d = (Delegate)p->ctx;
20
- const char * key = buf_str(&p->key);
20
+ const char *key = buf_str(&p->key);
21
21
  size_t len = buf_len(&p->key);
22
22
  volatile VALUE rkey;
23
23
 
@@ -48,6 +48,10 @@ static void open_object(ojParser p) {
48
48
  rb_funcall(((Delegate)p->ctx)->handler, oj_hash_start_id, 1, Qnil);
49
49
  }
50
50
 
51
+ static void open_object_loc(ojParser p) {
52
+ rb_funcall(((Delegate)p->ctx)->handler, oj_hash_start_id, 3, Qnil, LONG2FIX(p->line), LONG2FIX(p->cur - p->col));
53
+ }
54
+
51
55
  static void open_object_key(ojParser p) {
52
56
  Delegate d = (Delegate)p->ctx;
53
57
  volatile VALUE key = get_key(p);
@@ -56,10 +60,22 @@ static void open_object_key(ojParser p) {
56
60
  rb_funcall(d->handler, oj_hash_start_id, 1, key);
57
61
  }
58
62
 
63
+ static void open_object_loc_key(ojParser p) {
64
+ Delegate d = (Delegate)p->ctx;
65
+ volatile VALUE key = get_key(p);
66
+
67
+ push_key(d, key);
68
+ rb_funcall(d->handler, oj_hash_start_id, 3, key, LONG2FIX(p->line), LONG2FIX(p->cur - p->col));
69
+ }
70
+
59
71
  static void open_array(ojParser p) {
60
72
  rb_funcall(((Delegate)p->ctx)->handler, oj_array_start_id, 1, Qnil);
61
73
  }
62
74
 
75
+ static void open_array_loc(ojParser p) {
76
+ rb_funcall(((Delegate)p->ctx)->handler, oj_array_start_id, 3, Qnil, LONG2FIX(p->line), LONG2FIX(p->cur - p->col));
77
+ }
78
+
63
79
  static void open_array_key(ojParser p) {
64
80
  Delegate d = (Delegate)p->ctx;
65
81
  volatile VALUE key = get_key(p);
@@ -68,6 +84,14 @@ static void open_array_key(ojParser p) {
68
84
  rb_funcall(d->handler, oj_array_start_id, 1, key);
69
85
  }
70
86
 
87
+ static void open_array_loc_key(ojParser p) {
88
+ Delegate d = (Delegate)p->ctx;
89
+ volatile VALUE key = get_key(p);
90
+
91
+ push_key(d, key);
92
+ rb_funcall(d->handler, oj_array_start_id, 3, key, LONG2FIX(p->line), LONG2FIX(p->cur - p->col));
93
+ }
94
+
71
95
  static void close_object(ojParser p) {
72
96
  Delegate d = (Delegate)p->ctx;
73
97
  VALUE key = Qnil;
@@ -82,6 +106,20 @@ static void close_object(ojParser p) {
82
106
  rb_funcall(d->handler, oj_hash_end_id, 1, key);
83
107
  }
84
108
 
109
+ static void close_object_loc(ojParser p) {
110
+ Delegate d = (Delegate)p->ctx;
111
+ VALUE key = Qnil;
112
+
113
+ if (OBJECT_FUN == p->stack[p->depth]) {
114
+ d->tail--;
115
+ if (d->tail < d->keys) {
116
+ rb_raise(rb_eIndexError, "accessing key stack");
117
+ }
118
+ key = *d->tail;
119
+ }
120
+ rb_funcall(d->handler, oj_hash_end_id, 3, key, LONG2FIX(p->line), LONG2FIX(p->cur - p->col));
121
+ }
122
+
85
123
  static void close_array(ojParser p) {
86
124
  Delegate d = (Delegate)p->ctx;
87
125
  VALUE key = Qnil;
@@ -96,46 +134,160 @@ static void close_array(ojParser p) {
96
134
  rb_funcall(d->handler, oj_array_end_id, 1, key);
97
135
  }
98
136
 
137
+ static void close_array_loc(ojParser p) {
138
+ Delegate d = (Delegate)p->ctx;
139
+ VALUE key = Qnil;
140
+
141
+ if (OBJECT_FUN == p->stack[p->depth]) {
142
+ d->tail--;
143
+ if (d->tail < d->keys) {
144
+ rb_raise(rb_eIndexError, "accessing key stack");
145
+ }
146
+ key = *d->tail;
147
+ }
148
+ rb_funcall(d->handler, oj_array_end_id, 3, key, LONG2FIX(p->line), LONG2FIX(p->cur - p->col));
149
+ }
150
+
99
151
  static void add_null(ojParser p) {
100
152
  rb_funcall(((Delegate)p->ctx)->handler, oj_add_value_id, 2, Qnil, Qnil);
101
153
  }
102
154
 
155
+ static void add_null_loc(ojParser p) {
156
+ rb_funcall(((Delegate)p->ctx)->handler,
157
+ oj_add_value_id,
158
+ 4,
159
+ Qnil,
160
+ Qnil,
161
+ LONG2FIX(p->line),
162
+ LONG2FIX(p->cur - p->col));
163
+ }
164
+
103
165
  static void add_null_key(ojParser p) {
104
166
  rb_funcall(((Delegate)p->ctx)->handler, oj_add_value_id, 2, Qnil, get_key(p));
105
167
  }
106
168
 
169
+ static void add_null_key_loc(ojParser p) {
170
+ rb_funcall(((Delegate)p->ctx)->handler,
171
+ oj_add_value_id,
172
+ 4,
173
+ Qnil,
174
+ get_key(p),
175
+ LONG2FIX(p->line),
176
+ LONG2FIX(p->cur - p->col));
177
+ }
178
+
107
179
  static void add_true(ojParser p) {
108
180
  rb_funcall(((Delegate)p->ctx)->handler, oj_add_value_id, 2, Qtrue, Qnil);
109
181
  }
110
182
 
183
+ static void add_true_loc(ojParser p) {
184
+ rb_funcall(((Delegate)p->ctx)->handler,
185
+ oj_add_value_id,
186
+ 4,
187
+ Qtrue,
188
+ Qnil,
189
+ LONG2FIX(p->line),
190
+ LONG2FIX(p->cur - p->col));
191
+ }
192
+
111
193
  static void add_true_key(ojParser p) {
112
194
  rb_funcall(((Delegate)p->ctx)->handler, oj_add_value_id, 2, Qtrue, get_key(p));
113
195
  }
114
196
 
197
+ static void add_true_key_loc(ojParser p) {
198
+ rb_funcall(((Delegate)p->ctx)->handler,
199
+ oj_add_value_id,
200
+ 4,
201
+ Qtrue,
202
+ get_key(p),
203
+ LONG2FIX(p->line),
204
+ LONG2FIX(p->cur - p->col));
205
+ }
206
+
115
207
  static void add_false(ojParser p) {
116
208
  rb_funcall(((Delegate)p->ctx)->handler, oj_add_value_id, 2, Qfalse, Qnil);
117
209
  }
118
210
 
211
+ static void add_false_loc(ojParser p) {
212
+ rb_funcall(((Delegate)p->ctx)->handler,
213
+ oj_add_value_id,
214
+ 4,
215
+ Qfalse,
216
+ Qnil,
217
+ LONG2FIX(p->line),
218
+ LONG2FIX(p->cur - p->col));
219
+ }
220
+
119
221
  static void add_false_key(ojParser p) {
120
222
  rb_funcall(((Delegate)p->ctx)->handler, oj_add_value_id, 2, Qfalse, get_key(p));
121
223
  }
122
224
 
225
+ static void add_false_key_loc(ojParser p) {
226
+ rb_funcall(((Delegate)p->ctx)->handler,
227
+ oj_add_value_id,
228
+ 4,
229
+ Qfalse,
230
+ get_key(p),
231
+ LONG2FIX(p->line),
232
+ LONG2FIX(p->cur - p->col));
233
+ }
234
+
123
235
  static void add_int(ojParser p) {
124
236
  rb_funcall(((Delegate)p->ctx)->handler, oj_add_value_id, 2, LONG2NUM(p->num.fixnum), Qnil);
125
237
  }
126
238
 
239
+ static void add_int_loc(ojParser p) {
240
+ rb_funcall(((Delegate)p->ctx)->handler,
241
+ oj_add_value_id,
242
+ 4,
243
+ LONG2NUM(p->num.fixnum),
244
+ Qnil,
245
+ LONG2FIX(p->line),
246
+ LONG2FIX(p->cur - p->col));
247
+ }
248
+
127
249
  static void add_int_key(ojParser p) {
128
250
  rb_funcall(((Delegate)p->ctx)->handler, oj_add_value_id, 2, LONG2NUM(p->num.fixnum), get_key(p));
129
251
  }
130
252
 
253
+ static void add_int_key_loc(ojParser p) {
254
+ rb_funcall(((Delegate)p->ctx)->handler,
255
+ oj_add_value_id,
256
+ 4,
257
+ LONG2NUM(p->num.fixnum),
258
+ get_key(p),
259
+ LONG2FIX(p->line),
260
+ LONG2FIX(p->cur - p->col));
261
+ }
262
+
131
263
  static void add_float(ojParser p) {
132
264
  rb_funcall(((Delegate)p->ctx)->handler, oj_add_value_id, 2, rb_float_new(p->num.dub), Qnil);
133
265
  }
134
266
 
267
+ static void add_float_loc(ojParser p) {
268
+ rb_funcall(((Delegate)p->ctx)->handler,
269
+ oj_add_value_id,
270
+ 4,
271
+ rb_float_new(p->num.dub),
272
+ Qnil,
273
+ LONG2FIX(p->line),
274
+ LONG2FIX(p->cur - p->col));
275
+ }
276
+
135
277
  static void add_float_key(ojParser p) {
136
278
  rb_funcall(((Delegate)p->ctx)->handler, oj_add_value_id, 2, rb_float_new(p->num.dub), get_key(p));
137
279
  }
138
280
 
281
+ static void add_float_key_loc(ojParser p) {
282
+ rb_funcall(((Delegate)p->ctx)->handler,
283
+ oj_add_value_id,
284
+ 4,
285
+ rb_float_new(p->num.dub),
286
+ get_key(p),
287
+ LONG2FIX(p->line),
288
+ LONG2FIX(p->cur - p->col));
289
+ }
290
+
139
291
  static void add_big(ojParser p) {
140
292
  rb_funcall((VALUE)p->ctx,
141
293
  oj_add_value_id,
@@ -144,6 +296,16 @@ static void add_big(ojParser p) {
144
296
  Qnil);
145
297
  }
146
298
 
299
+ static void add_big_loc(ojParser p) {
300
+ rb_funcall((VALUE)p->ctx,
301
+ oj_add_value_id,
302
+ 4,
303
+ rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new(buf_str(&p->buf), buf_len(&p->buf))),
304
+ Qnil,
305
+ LONG2FIX(p->line),
306
+ LONG2FIX(p->cur - p->col));
307
+ }
308
+
147
309
  static void add_big_key(ojParser p) {
148
310
  rb_funcall((VALUE)p->ctx,
149
311
  oj_add_value_id,
@@ -152,10 +314,20 @@ static void add_big_key(ojParser p) {
152
314
  get_key(p));
153
315
  }
154
316
 
317
+ static void add_big_key_loc(ojParser p) {
318
+ rb_funcall((VALUE)p->ctx,
319
+ oj_add_value_id,
320
+ 4,
321
+ rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new(buf_str(&p->buf), buf_len(&p->buf))),
322
+ get_key(p),
323
+ LONG2FIX(p->line),
324
+ LONG2FIX(p->cur - p->col));
325
+ }
326
+
155
327
  static void add_str(ojParser p) {
156
328
  Delegate d = (Delegate)p->ctx;
157
329
  volatile VALUE rstr;
158
- const char * str = buf_str(&p->buf);
330
+ const char *str = buf_str(&p->buf);
159
331
  size_t len = buf_len(&p->buf);
160
332
 
161
333
  if (d->cache_str < len) {
@@ -166,10 +338,24 @@ static void add_str(ojParser p) {
166
338
  rb_funcall(d->handler, oj_add_value_id, 2, rstr, Qnil);
167
339
  }
168
340
 
341
+ static void add_str_loc(ojParser p) {
342
+ Delegate d = (Delegate)p->ctx;
343
+ volatile VALUE rstr;
344
+ const char *str = buf_str(&p->buf);
345
+ size_t len = buf_len(&p->buf);
346
+
347
+ if (d->cache_str < len) {
348
+ rstr = cache_intern(d->str_cache, str, len);
349
+ } else {
350
+ rstr = rb_utf8_str_new(str, len);
351
+ }
352
+ rb_funcall(d->handler, oj_add_value_id, 4, rstr, Qnil, LONG2FIX(p->line), LONG2FIX(p->cur - p->col));
353
+ }
354
+
169
355
  static void add_str_key(ojParser p) {
170
356
  Delegate d = (Delegate)p->ctx;
171
357
  volatile VALUE rstr;
172
- const char * str = buf_str(&p->buf);
358
+ const char *str = buf_str(&p->buf);
173
359
  size_t len = buf_len(&p->buf);
174
360
 
175
361
  if (d->cache_str < len) {
@@ -180,6 +366,20 @@ static void add_str_key(ojParser p) {
180
366
  rb_funcall(d->handler, oj_add_value_id, 2, rstr, get_key(p));
181
367
  }
182
368
 
369
+ static void add_str_key_loc(ojParser p) {
370
+ Delegate d = (Delegate)p->ctx;
371
+ volatile VALUE rstr;
372
+ const char *str = buf_str(&p->buf);
373
+ size_t len = buf_len(&p->buf);
374
+
375
+ if (d->cache_str < len) {
376
+ rstr = cache_intern(d->str_cache, str, len);
377
+ } else {
378
+ rstr = rb_utf8_str_new(str, len);
379
+ }
380
+ rb_funcall(d->handler, oj_add_value_id, 4, rstr, get_key(p), LONG2FIX(p->line), LONG2FIX(p->cur - p->col));
381
+ }
382
+
183
383
  static void reset(ojParser p) {
184
384
  Funcs end = p->funcs + 3;
185
385
  Funcs f;
@@ -210,53 +410,107 @@ static VALUE option(ojParser p, const char *key, VALUE value) {
210
410
  d->handler = value;
211
411
  reset(p);
212
412
  if (rb_respond_to(value, oj_hash_start_id)) {
213
- p->funcs[TOP_FUN].open_object = open_object;
214
- p->funcs[ARRAY_FUN].open_object = open_object;
215
- p->funcs[OBJECT_FUN].open_object = open_object_key;
413
+ if (1 == rb_obj_method_arity(value, oj_hash_start_id)) {
414
+ p->funcs[TOP_FUN].open_object = open_object;
415
+ p->funcs[ARRAY_FUN].open_object = open_object;
416
+ p->funcs[OBJECT_FUN].open_object = open_object_key;
417
+ } else {
418
+ p->funcs[TOP_FUN].open_object = open_object_loc;
419
+ p->funcs[ARRAY_FUN].open_object = open_object_loc;
420
+ p->funcs[OBJECT_FUN].open_object = open_object_loc_key;
421
+ }
216
422
  }
217
423
  if (rb_respond_to(value, oj_array_start_id)) {
218
- p->funcs[TOP_FUN].open_array = open_array;
219
- p->funcs[ARRAY_FUN].open_array = open_array;
220
- p->funcs[OBJECT_FUN].open_array = open_array_key;
424
+ if (1 == rb_obj_method_arity(value, oj_array_start_id)) {
425
+ p->funcs[TOP_FUN].open_array = open_array;
426
+ p->funcs[ARRAY_FUN].open_array = open_array;
427
+ p->funcs[OBJECT_FUN].open_array = open_array_key;
428
+ } else {
429
+ p->funcs[TOP_FUN].open_array = open_array_loc;
430
+ p->funcs[ARRAY_FUN].open_array = open_array_loc;
431
+ p->funcs[OBJECT_FUN].open_array = open_array_loc_key;
432
+ }
221
433
  }
222
434
  if (rb_respond_to(value, oj_hash_end_id)) {
223
- p->funcs[TOP_FUN].close_object = close_object;
224
- p->funcs[ARRAY_FUN].close_object = close_object;
225
- p->funcs[OBJECT_FUN].close_object = close_object;
435
+ if (1 == rb_obj_method_arity(value, oj_hash_end_id)) {
436
+ p->funcs[TOP_FUN].close_object = close_object;
437
+ p->funcs[ARRAY_FUN].close_object = close_object;
438
+ p->funcs[OBJECT_FUN].close_object = close_object;
439
+ } else {
440
+ p->funcs[TOP_FUN].close_object = close_object_loc;
441
+ p->funcs[ARRAY_FUN].close_object = close_object_loc;
442
+ p->funcs[OBJECT_FUN].close_object = close_object_loc;
443
+ }
226
444
  }
227
445
  if (rb_respond_to(value, oj_array_end_id)) {
228
- p->funcs[TOP_FUN].close_array = close_array;
229
- p->funcs[ARRAY_FUN].close_array = close_array;
230
- p->funcs[OBJECT_FUN].close_array = close_array;
446
+ if (1 == rb_obj_method_arity(value, oj_array_end_id)) {
447
+ p->funcs[TOP_FUN].close_array = close_array;
448
+ p->funcs[ARRAY_FUN].close_array = close_array;
449
+ p->funcs[OBJECT_FUN].close_array = close_array;
450
+ } else {
451
+ p->funcs[TOP_FUN].close_array = close_array_loc;
452
+ p->funcs[ARRAY_FUN].close_array = close_array_loc;
453
+ p->funcs[OBJECT_FUN].close_array = close_array_loc;
454
+ }
231
455
  }
232
456
  if (rb_respond_to(value, oj_add_value_id)) {
233
- p->funcs[TOP_FUN].add_null = add_null;
234
- p->funcs[ARRAY_FUN].add_null = add_null;
235
- p->funcs[OBJECT_FUN].add_null = add_null_key;
236
-
237
- p->funcs[TOP_FUN].add_true = add_true;
238
- p->funcs[ARRAY_FUN].add_true = add_true;
239
- p->funcs[OBJECT_FUN].add_true = add_true_key;
240
-
241
- p->funcs[TOP_FUN].add_false = add_false;
242
- p->funcs[ARRAY_FUN].add_false = add_false;
243
- p->funcs[OBJECT_FUN].add_false = add_false_key;
244
-
245
- p->funcs[TOP_FUN].add_int = add_int;
246
- p->funcs[ARRAY_FUN].add_int = add_int;
247
- p->funcs[OBJECT_FUN].add_int = add_int_key;
248
-
249
- p->funcs[TOP_FUN].add_float = add_float;
250
- p->funcs[ARRAY_FUN].add_float = add_float;
251
- p->funcs[OBJECT_FUN].add_float = add_float_key;
252
-
253
- p->funcs[TOP_FUN].add_big = add_big;
254
- p->funcs[ARRAY_FUN].add_big = add_big;
255
- p->funcs[OBJECT_FUN].add_big = add_big_key;
256
-
257
- p->funcs[TOP_FUN].add_str = add_str;
258
- p->funcs[ARRAY_FUN].add_str = add_str;
259
- p->funcs[OBJECT_FUN].add_str = add_str_key;
457
+ if (2 == rb_obj_method_arity(value, oj_add_value_id)) {
458
+ p->funcs[TOP_FUN].add_null = add_null;
459
+ p->funcs[ARRAY_FUN].add_null = add_null;
460
+ p->funcs[OBJECT_FUN].add_null = add_null_key;
461
+
462
+ p->funcs[TOP_FUN].add_true = add_true;
463
+ p->funcs[ARRAY_FUN].add_true = add_true;
464
+ p->funcs[OBJECT_FUN].add_true = add_true_key;
465
+
466
+ p->funcs[TOP_FUN].add_false = add_false;
467
+ p->funcs[ARRAY_FUN].add_false = add_false;
468
+ p->funcs[OBJECT_FUN].add_false = add_false_key;
469
+
470
+ p->funcs[TOP_FUN].add_int = add_int;
471
+ p->funcs[ARRAY_FUN].add_int = add_int;
472
+ p->funcs[OBJECT_FUN].add_int = add_int_key;
473
+
474
+ p->funcs[TOP_FUN].add_float = add_float;
475
+ p->funcs[ARRAY_FUN].add_float = add_float;
476
+ p->funcs[OBJECT_FUN].add_float = add_float_key;
477
+
478
+ p->funcs[TOP_FUN].add_big = add_big;
479
+ p->funcs[ARRAY_FUN].add_big = add_big;
480
+ p->funcs[OBJECT_FUN].add_big = add_big_key;
481
+
482
+ p->funcs[TOP_FUN].add_str = add_str;
483
+ p->funcs[ARRAY_FUN].add_str = add_str;
484
+ p->funcs[OBJECT_FUN].add_str = add_str_key;
485
+ } else {
486
+ p->funcs[TOP_FUN].add_null = add_null_loc;
487
+ p->funcs[ARRAY_FUN].add_null = add_null_loc;
488
+ p->funcs[OBJECT_FUN].add_null = add_null_key_loc;
489
+
490
+ p->funcs[TOP_FUN].add_true = add_true_loc;
491
+ p->funcs[ARRAY_FUN].add_true = add_true_loc;
492
+ p->funcs[OBJECT_FUN].add_true = add_true_key_loc;
493
+
494
+ p->funcs[TOP_FUN].add_false = add_false_loc;
495
+ p->funcs[ARRAY_FUN].add_false = add_false_loc;
496
+ p->funcs[OBJECT_FUN].add_false = add_false_key_loc;
497
+
498
+ p->funcs[TOP_FUN].add_int = add_int_loc;
499
+ p->funcs[ARRAY_FUN].add_int = add_int_loc;
500
+ p->funcs[OBJECT_FUN].add_int = add_int_key_loc;
501
+
502
+ p->funcs[TOP_FUN].add_float = add_float_loc;
503
+ p->funcs[ARRAY_FUN].add_float = add_float_loc;
504
+ p->funcs[OBJECT_FUN].add_float = add_float_key_loc;
505
+
506
+ p->funcs[TOP_FUN].add_big = add_big_loc;
507
+ p->funcs[ARRAY_FUN].add_big = add_big_loc;
508
+ p->funcs[OBJECT_FUN].add_big = add_big_key_loc;
509
+
510
+ p->funcs[TOP_FUN].add_str = add_str_loc;
511
+ p->funcs[ARRAY_FUN].add_str = add_str_loc;
512
+ p->funcs[OBJECT_FUN].add_str = add_str_key_loc;
513
+ }
260
514
  }
261
515
  return Qnil;
262
516
  }
@@ -313,7 +567,7 @@ static void mark(ojParser p) {
313
567
  return;
314
568
  }
315
569
  Delegate d = (Delegate)p->ctx;
316
- VALUE *kp;
570
+ VALUE *kp;
317
571
 
318
572
  cache_mark(d->str_cache);
319
573
  if (Qnil != d->handler) {
data/ext/oj/sparse.c CHANGED
@@ -953,7 +953,11 @@ CLEANUP:
953
953
  }
954
954
  stack_cleanup(&pi->stack);
955
955
  if (0 != fd) {
956
+ #ifdef _WIN32
957
+ rb_w32_close(fd);
958
+ #else
956
959
  close(fd);
960
+ #endif
957
961
  }
958
962
  if (err_has(&pi->err)) {
959
963
  rb_set_errinfo(Qnil);
data/ext/oj/strict.c CHANGED
@@ -50,13 +50,13 @@ VALUE oj_calc_hash_key(ParseInfo pi, Val parent) {
50
50
  }
51
51
 
52
52
  static void hash_end(ParseInfo pi) {
53
- if (Yes == pi->options.trace) {
53
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
54
54
  oj_trace_parse_hash_end(pi, __FILE__, __LINE__);
55
55
  }
56
56
  }
57
57
 
58
58
  static void array_end(ParseInfo pi) {
59
- if (Yes == pi->options.trace) {
59
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
60
60
  oj_trace_parse_array_end(pi, __FILE__, __LINE__);
61
61
  }
62
62
  }
@@ -66,7 +66,7 @@ static VALUE noop_hash_key(ParseInfo pi, const char *key, size_t klen) {
66
66
  }
67
67
 
68
68
  static void add_value(ParseInfo pi, VALUE val) {
69
- if (Yes == pi->options.trace) {
69
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
70
70
  oj_trace_parse_call("add_value", pi, __FILE__, __LINE__, val);
71
71
  }
72
72
  pi->stack.head->val = val;
@@ -76,7 +76,7 @@ static void add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig
76
76
  volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
77
77
 
78
78
  pi->stack.head->val = rstr;
79
- if (Yes == pi->options.trace) {
79
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
80
80
  oj_trace_parse_call("add_string", pi, __FILE__, __LINE__, rstr);
81
81
  }
82
82
  }
@@ -86,7 +86,7 @@ static void add_num(ParseInfo pi, NumInfo ni) {
86
86
  oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number or other value");
87
87
  }
88
88
  pi->stack.head->val = oj_num_as_value(ni);
89
- if (Yes == pi->options.trace) {
89
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
90
90
  oj_trace_parse_call("add_number", pi, __FILE__, __LINE__, pi->stack.head->val);
91
91
  }
92
92
  }
@@ -95,7 +95,7 @@ static VALUE start_hash(ParseInfo pi) {
95
95
  if (Qnil != pi->options.hash_class) {
96
96
  return rb_class_new_instance(0, NULL, pi->options.hash_class);
97
97
  }
98
- if (Yes == pi->options.trace) {
98
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
99
99
  oj_trace_parse_in("start_hash", pi, __FILE__, __LINE__);
100
100
  }
101
101
  return rb_hash_new();
@@ -107,7 +107,7 @@ static void hash_set_cstr(ParseInfo pi, Val parent, const char *str, size_t len,
107
107
  rb_hash_aset(stack_peek(&pi->stack)->val,
108
108
  oj_calc_hash_key(pi, parent),
109
109
  rstr);
110
- if (Yes == pi->options.trace) {
110
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
111
111
  oj_trace_parse_call("set_string", pi, __FILE__, __LINE__, rstr);
112
112
  }
113
113
  }
@@ -122,7 +122,7 @@ static void hash_set_num(ParseInfo pi, Val parent, NumInfo ni) {
122
122
  rb_hash_aset(stack_peek(&pi->stack)->val,
123
123
  oj_calc_hash_key(pi, parent),
124
124
  v);
125
- if (Yes == pi->options.trace) {
125
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
126
126
  oj_trace_parse_call("set_number", pi, __FILE__, __LINE__, v);
127
127
  }
128
128
  }
@@ -131,13 +131,13 @@ static void hash_set_value(ParseInfo pi, Val parent, VALUE value) {
131
131
  rb_hash_aset(stack_peek(&pi->stack)->val,
132
132
  oj_calc_hash_key(pi, parent),
133
133
  value);
134
- if (Yes == pi->options.trace) {
134
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
135
135
  oj_trace_parse_call("set_value", pi, __FILE__, __LINE__, value);
136
136
  }
137
137
  }
138
138
 
139
139
  static VALUE start_array(ParseInfo pi) {
140
- if (Yes == pi->options.trace) {
140
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
141
141
  oj_trace_parse_in("start_array", pi, __FILE__, __LINE__);
142
142
  }
143
143
  return rb_ary_new();
@@ -147,7 +147,7 @@ static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const c
147
147
  volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
148
148
 
149
149
  rb_ary_push(stack_peek(&pi->stack)->val, rstr);
150
- if (Yes == pi->options.trace) {
150
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
151
151
  oj_trace_parse_call("append_string", pi, __FILE__, __LINE__, rstr);
152
152
  }
153
153
  }
@@ -160,14 +160,14 @@ static void array_append_num(ParseInfo pi, NumInfo ni) {
160
160
  }
161
161
  v = oj_num_as_value(ni);
162
162
  rb_ary_push(stack_peek(&pi->stack)->val, v);
163
- if (Yes == pi->options.trace) {
163
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
164
164
  oj_trace_parse_call("append_number", pi, __FILE__, __LINE__, v);
165
165
  }
166
166
  }
167
167
 
168
168
  static void array_append_value(ParseInfo pi, VALUE value) {
169
169
  rb_ary_push(stack_peek(&pi->stack)->val, value);
170
- if (Yes == pi->options.trace) {
170
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
171
171
  oj_trace_parse_call("append_value", pi, __FILE__, __LINE__, value);
172
172
  }
173
173
  }
data/ext/oj/validate.c CHANGED
@@ -2,50 +2,45 @@
2
2
 
3
3
  #include "parser.h"
4
4
 
5
- static void
6
- noop(ojParser p) {
5
+ static void noop(ojParser p) {
7
6
  }
8
7
 
9
- static VALUE
10
- option(ojParser p, const char *key, VALUE value) {
8
+ static VALUE option(ojParser p, const char *key, VALUE value) {
11
9
  rb_raise(rb_eArgError, "%s is not an option for the validate delegate", key);
12
10
  return Qnil;
13
11
  }
14
12
 
15
- static VALUE
16
- result(ojParser p) {
13
+ static VALUE result(ojParser p) {
17
14
  return Qnil;
18
15
  }
19
16
 
20
- static void
21
- dfree(ojParser p) {
17
+ static void dfree(ojParser p) {
22
18
  }
23
19
 
24
- static void
25
- mark(ojParser p) {
20
+ static void mark(ojParser p) {
26
21
  }
27
22
 
28
23
  void oj_set_parser_validator(ojParser p) {
29
- p->ctx = NULL;
30
- Funcs end = p->funcs + 3;
24
+ Funcs end = p->funcs + 3;
31
25
  Funcs f;
26
+ p->ctx = NULL;
32
27
 
33
28
  for (f = p->funcs; f < end; f++) {
34
- f->add_null = noop;
35
- f->add_true = noop;
36
- f->add_false = noop;
37
- f->add_int = noop;
38
- f->add_float = noop;
39
- f->add_big = noop;
40
- f->add_str = noop;
41
- f->open_array = noop;
42
- f->close_array = noop;
43
- f->open_object = noop;
44
- f->close_object = noop;
29
+ f->add_null = noop;
30
+ f->add_true = noop;
31
+ f->add_false = noop;
32
+ f->add_int = noop;
33
+ f->add_float = noop;
34
+ f->add_big = noop;
35
+ f->add_str = noop;
36
+ f->open_array = noop;
37
+ f->close_array = noop;
38
+ f->open_object = noop;
39
+ f->close_object = noop;
45
40
  }
46
41
  p->option = option;
47
42
  p->result = result;
48
- p->free = dfree;
49
- p->mark = mark;
50
- p->start = noop;
43
+ p->free = dfree;
44
+ p->mark = mark;
45
+ p->start = noop;
51
46
  }