oj 3.13.2 → 3.13.3

Sign up to get free protection for your applications and to get access to all the features.
data/ext/oj/oj.c CHANGED
@@ -190,7 +190,7 @@ struct _options oj_default_options = {
190
190
  false, // sec_prec_set
191
191
  No, // ignore_under
192
192
  Yes, // cache_keys
193
- 3, // cache_str
193
+ 0, // cache_str
194
194
  0, // int_range_min
195
195
  0, // int_range_max
196
196
  oj_json_class, // create_id
@@ -288,7 +288,7 @@ struct _options oj_default_options = {
288
288
  * - *:ignore_under* [_Boolean_] if true then attributes that start with _ are ignored when dumping in
289
289
  *object or custom mode.
290
290
  * - *:cache_keys* [_Boolean_] if true then hash keys are cached
291
- * - *:cache_str* [_Fixnum_] maximum string value length to cache
291
+ * - *:cache_str* [_Fixnum_] maximum string value length to cache (strings less than this are cached)
292
292
  * - *:integer_range* [_Range_] Dump integers outside range as strings.
293
293
  * - *:trace* [_true,_|_false_] Trace all load and dump calls, default is false (trace is off)
294
294
  * - *:safe* [_true,_|_false_] Safe mimic breaks JSON mimic to be safer, default is false (safe is
@@ -571,7 +571,7 @@ static VALUE get_def_opts(VALUE self) {
571
571
  * - *:ignore_under* [_Boolean_] if true then attributes that start with _ are ignored when
572
572
  *dumping in object or custom mode.
573
573
  * - *:cache_keys* [_Boolean_] if true then hash keys are cached
574
- * - *:cache_str* [_Fixnum_] maximum string vsalue length to cache
574
+ * - *:cache_str* [_Fixnum_] maximum string value length to cache (strings less than this are cached)
575
575
  * - *:integer_range* [_Range_] Dump integers outside range as strings.
576
576
  * - *:trace* [_Boolean_] turn trace on or off.
577
577
  * - *:safe* [_Boolean_] turn safe mimic on or off.
data/ext/oj/parser.c CHANGED
@@ -1,8 +1,9 @@
1
1
  // Copyright (c) 2020, 2021, Peter Ohler, All rights reserved.
2
2
 
3
+ #include "parser.h"
4
+
3
5
  #include <fcntl.h>
4
6
 
5
- #include "parser.h"
6
7
  #include "oj.h"
7
8
 
8
9
  #define DEBUG 0
@@ -384,87 +385,44 @@ static const byte hex_map[256] = "\
384
385
  ................................\
385
386
  ................................";
386
387
 
387
- static long double pow_map[401] = {1.0L, 1.0e1L, 1.0e2L, 1.0e3L, 1.0e4L,
388
- 1.0e5L, 1.0e6L, 1.0e7L, 1.0e8L, 1.0e9L, // 00
389
- 1.0e10L, 1.0e11L, 1.0e12L, 1.0e13L, 1.0e14L,
390
- 1.0e15L, 1.0e16L, 1.0e17L, 1.0e18L, 1.0e19L, // 10
391
- 1.0e20L, 1.0e21L, 1.0e22L, 1.0e23L, 1.0e24L,
392
- 1.0e25L, 1.0e26L, 1.0e27L, 1.0e28L, 1.0e29L, // 20
393
- 1.0e30L, 1.0e31L, 1.0e32L, 1.0e33L, 1.0e34L,
394
- 1.0e35L, 1.0e36L, 1.0e37L, 1.0e38L, 1.0e39L, // 30
395
- 1.0e40L, 1.0e41L, 1.0e42L, 1.0e43L, 1.0e44L,
396
- 1.0e45L, 1.0e46L, 1.0e47L, 1.0e48L, 1.0e49L, // 40
397
- 1.0e50L, 1.0e51L, 1.0e52L, 1.0e53L, 1.0e54L,
398
- 1.0e55L, 1.0e56L, 1.0e57L, 1.0e58L, 1.0e59L, // 50
399
- 1.0e60L, 1.0e61L, 1.0e62L, 1.0e63L, 1.0e64L,
400
- 1.0e65L, 1.0e66L, 1.0e67L, 1.0e68L, 1.0e69L, // 60
401
- 1.0e70L, 1.0e71L, 1.0e72L, 1.0e73L, 1.0e74L,
402
- 1.0e75L, 1.0e76L, 1.0e77L, 1.0e78L, 1.0e79L, // 70
403
- 1.0e80L, 1.0e81L, 1.0e82L, 1.0e83L, 1.0e84L,
404
- 1.0e85L, 1.0e86L, 1.0e87L, 1.0e88L, 1.0e89L, // 80
405
- 1.0e90L, 1.0e91L, 1.0e92L, 1.0e93L, 1.0e94L,
406
- 1.0e95L, 1.0e96L, 1.0e97L, 1.0e98L, 1.0e99L, // 90
407
- 1.0e100L, 1.0e101L, 1.0e102L, 1.0e103L, 1.0e104L,
408
- 1.0e105L, 1.0e106L, 1.0e107L, 1.0e108L, 1.0e109L, // 100
409
- 1.0e110L, 1.0e111L, 1.0e112L, 1.0e113L, 1.0e114L,
410
- 1.0e115L, 1.0e116L, 1.0e117L, 1.0e118L, 1.0e119L, // 110
411
- 1.0e120L, 1.0e121L, 1.0e122L, 1.0e123L, 1.0e124L,
412
- 1.0e125L, 1.0e126L, 1.0e127L, 1.0e128L, 1.0e129L, // 120
413
- 1.0e130L, 1.0e131L, 1.0e132L, 1.0e133L, 1.0e134L,
414
- 1.0e135L, 1.0e136L, 1.0e137L, 1.0e138L, 1.0e139L, // 130
415
- 1.0e140L, 1.0e141L, 1.0e142L, 1.0e143L, 1.0e144L,
416
- 1.0e145L, 1.0e146L, 1.0e147L, 1.0e148L, 1.0e149L, // 140
417
- 1.0e150L, 1.0e151L, 1.0e152L, 1.0e153L, 1.0e154L,
418
- 1.0e155L, 1.0e156L, 1.0e157L, 1.0e158L, 1.0e159L, // 150
419
- 1.0e160L, 1.0e161L, 1.0e162L, 1.0e163L, 1.0e164L,
420
- 1.0e165L, 1.0e166L, 1.0e167L, 1.0e168L, 1.0e169L, // 160
421
- 1.0e170L, 1.0e171L, 1.0e172L, 1.0e173L, 1.0e174L,
422
- 1.0e175L, 1.0e176L, 1.0e177L, 1.0e178L, 1.0e179L, // 170
423
- 1.0e180L, 1.0e181L, 1.0e182L, 1.0e183L, 1.0e184L,
424
- 1.0e185L, 1.0e186L, 1.0e187L, 1.0e188L, 1.0e189L, // 180
425
- 1.0e190L, 1.0e191L, 1.0e192L, 1.0e193L, 1.0e194L,
426
- 1.0e195L, 1.0e196L, 1.0e197L, 1.0e198L, 1.0e199L, // 190
427
- 1.0e200L, 1.0e201L, 1.0e202L, 1.0e203L, 1.0e204L,
428
- 1.0e205L, 1.0e206L, 1.0e207L, 1.0e208L, 1.0e209L, // 200
429
- 1.0e210L, 1.0e211L, 1.0e212L, 1.0e213L, 1.0e214L,
430
- 1.0e215L, 1.0e216L, 1.0e217L, 1.0e218L, 1.0e219L, // 210
431
- 1.0e220L, 1.0e221L, 1.0e222L, 1.0e223L, 1.0e224L,
432
- 1.0e225L, 1.0e226L, 1.0e227L, 1.0e228L, 1.0e229L, // 220
433
- 1.0e230L, 1.0e231L, 1.0e232L, 1.0e233L, 1.0e234L,
434
- 1.0e235L, 1.0e236L, 1.0e237L, 1.0e238L, 1.0e239L, // 230
435
- 1.0e240L, 1.0e241L, 1.0e242L, 1.0e243L, 1.0e244L,
436
- 1.0e245L, 1.0e246L, 1.0e247L, 1.0e248L, 1.0e249L, // 240
437
- 1.0e250L, 1.0e251L, 1.0e252L, 1.0e253L, 1.0e254L,
438
- 1.0e255L, 1.0e256L, 1.0e257L, 1.0e258L, 1.0e259L, // 250
439
- 1.0e260L, 1.0e261L, 1.0e262L, 1.0e263L, 1.0e264L,
440
- 1.0e265L, 1.0e266L, 1.0e267L, 1.0e268L, 1.0e269L, // 260
441
- 1.0e270L, 1.0e271L, 1.0e272L, 1.0e273L, 1.0e274L,
442
- 1.0e275L, 1.0e276L, 1.0e277L, 1.0e278L, 1.0e279L, // 270
443
- 1.0e280L, 1.0e281L, 1.0e282L, 1.0e283L, 1.0e284L,
444
- 1.0e285L, 1.0e286L, 1.0e287L, 1.0e288L, 1.0e289L, // 280
445
- 1.0e290L, 1.0e291L, 1.0e292L, 1.0e293L, 1.0e294L,
446
- 1.0e295L, 1.0e296L, 1.0e297L, 1.0e298L, 1.0e299L, // 290
447
- 1.0e300L, 1.0e301L, 1.0e302L, 1.0e303L, 1.0e304L,
448
- 1.0e305L, 1.0e306L, 1.0e307L, 1.0e308L, 1.0e309L, // 300
449
- 1.0e310L, 1.0e311L, 1.0e312L, 1.0e313L, 1.0e314L,
450
- 1.0e315L, 1.0e316L, 1.0e317L, 1.0e318L, 1.0e319L, // 310
451
- 1.0e320L, 1.0e321L, 1.0e322L, 1.0e323L, 1.0e324L,
452
- 1.0e325L, 1.0e326L, 1.0e327L, 1.0e328L, 1.0e329L, // 320
453
- 1.0e330L, 1.0e331L, 1.0e332L, 1.0e333L, 1.0e334L,
454
- 1.0e335L, 1.0e336L, 1.0e337L, 1.0e338L, 1.0e339L, // 330
455
- 1.0e340L, 1.0e341L, 1.0e342L, 1.0e343L, 1.0e344L,
456
- 1.0e345L, 1.0e346L, 1.0e347L, 1.0e348L, 1.0e349L, // 340
457
- 1.0e350L, 1.0e351L, 1.0e352L, 1.0e353L, 1.0e354L,
458
- 1.0e355L, 1.0e356L, 1.0e357L, 1.0e358L, 1.0e359L, // 350
459
- 1.0e360L, 1.0e361L, 1.0e362L, 1.0e363L, 1.0e364L,
460
- 1.0e365L, 1.0e366L, 1.0e367L, 1.0e368L, 1.0e369L, // 360
461
- 1.0e370L, 1.0e371L, 1.0e372L, 1.0e373L, 1.0e374L,
462
- 1.0e375L, 1.0e376L, 1.0e377L, 1.0e378L, 1.0e379L, // 370
463
- 1.0e380L, 1.0e381L, 1.0e382L, 1.0e383L, 1.0e384L,
464
- 1.0e385L, 1.0e386L, 1.0e387L, 1.0e388L, 1.0e389L, // 380
465
- 1.0e390L, 1.0e391L, 1.0e392L, 1.0e393L, 1.0e394L,
466
- 1.0e395L, 1.0e396L, 1.0e397L, 1.0e398L, 1.0e399L, // 390
467
- 1.0e400L};
388
+ static long double pow_map[401] = {
389
+ 1.0L, 1.0e1L, 1.0e2L, 1.0e3L, 1.0e4L, 1.0e5L, 1.0e6L, 1.0e7L, 1.0e8L, 1.0e9L, 1.0e10L,
390
+ 1.0e11L, 1.0e12L, 1.0e13L, 1.0e14L, 1.0e15L, 1.0e16L, 1.0e17L, 1.0e18L, 1.0e19L, 1.0e20L, 1.0e21L,
391
+ 1.0e22L, 1.0e23L, 1.0e24L, 1.0e25L, 1.0e26L, 1.0e27L, 1.0e28L, 1.0e29L, 1.0e30L, 1.0e31L, 1.0e32L,
392
+ 1.0e33L, 1.0e34L, 1.0e35L, 1.0e36L, 1.0e37L, 1.0e38L, 1.0e39L, 1.0e40L, 1.0e41L, 1.0e42L, 1.0e43L,
393
+ 1.0e44L, 1.0e45L, 1.0e46L, 1.0e47L, 1.0e48L, 1.0e49L, 1.0e50L, 1.0e51L, 1.0e52L, 1.0e53L, 1.0e54L,
394
+ 1.0e55L, 1.0e56L, 1.0e57L, 1.0e58L, 1.0e59L, 1.0e60L, 1.0e61L, 1.0e62L, 1.0e63L, 1.0e64L, 1.0e65L,
395
+ 1.0e66L, 1.0e67L, 1.0e68L, 1.0e69L, 1.0e70L, 1.0e71L, 1.0e72L, 1.0e73L, 1.0e74L, 1.0e75L, 1.0e76L,
396
+ 1.0e77L, 1.0e78L, 1.0e79L, 1.0e80L, 1.0e81L, 1.0e82L, 1.0e83L, 1.0e84L, 1.0e85L, 1.0e86L, 1.0e87L,
397
+ 1.0e88L, 1.0e89L, 1.0e90L, 1.0e91L, 1.0e92L, 1.0e93L, 1.0e94L, 1.0e95L, 1.0e96L, 1.0e97L, 1.0e98L,
398
+ 1.0e99L, 1.0e100L, 1.0e101L, 1.0e102L, 1.0e103L, 1.0e104L, 1.0e105L, 1.0e106L, 1.0e107L, 1.0e108L, 1.0e109L,
399
+ 1.0e110L, 1.0e111L, 1.0e112L, 1.0e113L, 1.0e114L, 1.0e115L, 1.0e116L, 1.0e117L, 1.0e118L, 1.0e119L, 1.0e120L,
400
+ 1.0e121L, 1.0e122L, 1.0e123L, 1.0e124L, 1.0e125L, 1.0e126L, 1.0e127L, 1.0e128L, 1.0e129L, 1.0e130L, 1.0e131L,
401
+ 1.0e132L, 1.0e133L, 1.0e134L, 1.0e135L, 1.0e136L, 1.0e137L, 1.0e138L, 1.0e139L, 1.0e140L, 1.0e141L, 1.0e142L,
402
+ 1.0e143L, 1.0e144L, 1.0e145L, 1.0e146L, 1.0e147L, 1.0e148L, 1.0e149L, 1.0e150L, 1.0e151L, 1.0e152L, 1.0e153L,
403
+ 1.0e154L, 1.0e155L, 1.0e156L, 1.0e157L, 1.0e158L, 1.0e159L, 1.0e160L, 1.0e161L, 1.0e162L, 1.0e163L, 1.0e164L,
404
+ 1.0e165L, 1.0e166L, 1.0e167L, 1.0e168L, 1.0e169L, 1.0e170L, 1.0e171L, 1.0e172L, 1.0e173L, 1.0e174L, 1.0e175L,
405
+ 1.0e176L, 1.0e177L, 1.0e178L, 1.0e179L, 1.0e180L, 1.0e181L, 1.0e182L, 1.0e183L, 1.0e184L, 1.0e185L, 1.0e186L,
406
+ 1.0e187L, 1.0e188L, 1.0e189L, 1.0e190L, 1.0e191L, 1.0e192L, 1.0e193L, 1.0e194L, 1.0e195L, 1.0e196L, 1.0e197L,
407
+ 1.0e198L, 1.0e199L, 1.0e200L, 1.0e201L, 1.0e202L, 1.0e203L, 1.0e204L, 1.0e205L, 1.0e206L, 1.0e207L, 1.0e208L,
408
+ 1.0e209L, 1.0e210L, 1.0e211L, 1.0e212L, 1.0e213L, 1.0e214L, 1.0e215L, 1.0e216L, 1.0e217L, 1.0e218L, 1.0e219L,
409
+ 1.0e220L, 1.0e221L, 1.0e222L, 1.0e223L, 1.0e224L, 1.0e225L, 1.0e226L, 1.0e227L, 1.0e228L, 1.0e229L, 1.0e230L,
410
+ 1.0e231L, 1.0e232L, 1.0e233L, 1.0e234L, 1.0e235L, 1.0e236L, 1.0e237L, 1.0e238L, 1.0e239L, 1.0e240L, 1.0e241L,
411
+ 1.0e242L, 1.0e243L, 1.0e244L, 1.0e245L, 1.0e246L, 1.0e247L, 1.0e248L, 1.0e249L, 1.0e250L, 1.0e251L, 1.0e252L,
412
+ 1.0e253L, 1.0e254L, 1.0e255L, 1.0e256L, 1.0e257L, 1.0e258L, 1.0e259L, 1.0e260L, 1.0e261L, 1.0e262L, 1.0e263L,
413
+ 1.0e264L, 1.0e265L, 1.0e266L, 1.0e267L, 1.0e268L, 1.0e269L, 1.0e270L, 1.0e271L, 1.0e272L, 1.0e273L, 1.0e274L,
414
+ 1.0e275L, 1.0e276L, 1.0e277L, 1.0e278L, 1.0e279L, 1.0e280L, 1.0e281L, 1.0e282L, 1.0e283L, 1.0e284L, 1.0e285L,
415
+ 1.0e286L, 1.0e287L, 1.0e288L, 1.0e289L, 1.0e290L, 1.0e291L, 1.0e292L, 1.0e293L, 1.0e294L, 1.0e295L, 1.0e296L,
416
+ 1.0e297L, 1.0e298L, 1.0e299L, 1.0e300L, 1.0e301L, 1.0e302L, 1.0e303L, 1.0e304L, 1.0e305L, 1.0e306L, 1.0e307L,
417
+ 1.0e308L, 1.0e309L, 1.0e310L, 1.0e311L, 1.0e312L, 1.0e313L, 1.0e314L, 1.0e315L, 1.0e316L, 1.0e317L, 1.0e318L,
418
+ 1.0e319L, 1.0e320L, 1.0e321L, 1.0e322L, 1.0e323L, 1.0e324L, 1.0e325L, 1.0e326L, 1.0e327L, 1.0e328L, 1.0e329L,
419
+ 1.0e330L, 1.0e331L, 1.0e332L, 1.0e333L, 1.0e334L, 1.0e335L, 1.0e336L, 1.0e337L, 1.0e338L, 1.0e339L, 1.0e340L,
420
+ 1.0e341L, 1.0e342L, 1.0e343L, 1.0e344L, 1.0e345L, 1.0e346L, 1.0e347L, 1.0e348L, 1.0e349L, 1.0e350L, 1.0e351L,
421
+ 1.0e352L, 1.0e353L, 1.0e354L, 1.0e355L, 1.0e356L, 1.0e357L, 1.0e358L, 1.0e359L, 1.0e360L, 1.0e361L, 1.0e362L,
422
+ 1.0e363L, 1.0e364L, 1.0e365L, 1.0e366L, 1.0e367L, 1.0e368L, 1.0e369L, 1.0e370L, 1.0e371L, 1.0e372L, 1.0e373L,
423
+ 1.0e374L, 1.0e375L, 1.0e376L, 1.0e377L, 1.0e378L, 1.0e379L, 1.0e380L, 1.0e381L, 1.0e382L, 1.0e383L, 1.0e384L,
424
+ 1.0e385L, 1.0e386L, 1.0e387L, 1.0e388L, 1.0e389L, 1.0e390L, 1.0e391L, 1.0e392L, 1.0e393L, 1.0e394L, 1.0e395L,
425
+ 1.0e396L, 1.0e397L, 1.0e398L, 1.0e399L, 1.0e400L};
468
426
 
469
427
  static VALUE parser_class;
470
428
 
@@ -591,7 +549,7 @@ static void big_change(ojParser p) {
591
549
  int len = 0;
592
550
 
593
551
  buf[sizeof(buf) - 1] = '\0';
594
- p->buf.tail = p->buf.head;
552
+ p->buf.tail = p->buf.head;
595
553
  switch (p->type) {
596
554
  case OJ_INT:
597
555
  // If an int then it will fit in the num.raw so no need to check length;
@@ -646,7 +604,7 @@ static void big_change(ojParser p) {
646
604
  static void parse(ojParser p, const byte *json) {
647
605
  const byte *start;
648
606
  const byte *b = json;
649
- int i;
607
+ int i;
650
608
 
651
609
  #if DEBUG
652
610
  printf("*** parse - mode: %c %s\n", p->map[256], (const char *)json);
@@ -890,7 +848,7 @@ static void parse(ojParser p, const byte *json) {
890
848
  }
891
849
  buf_append_string(&p->buf, (const char *)start, b - start);
892
850
  b--;
893
- break;
851
+ break;
894
852
  case BIG_E:
895
853
  buf_append(&p->buf, *b);
896
854
  p->map = big_exp_sign_map;
@@ -1205,8 +1163,7 @@ static VALUE parser_new(VALUE self, VALUE mode) {
1205
1163
  mode = rb_sym2str(mode);
1206
1164
  // fall through
1207
1165
  case RUBY_T_STRING: ms = RSTRING_PTR(mode); break;
1208
- default:
1209
- rb_raise(rb_eArgError, "mode must be :validate, :usual, :saj, or :object");
1166
+ default: rb_raise(rb_eArgError, "mode must be :validate, :usual, :saj, or :object");
1210
1167
  }
1211
1168
  if (0 == strcmp("usual", ms) || 0 == strcmp("standard", ms) || 0 == strcmp("strict", ms) ||
1212
1169
  0 == strcmp("compat", ms)) {
@@ -1238,7 +1195,8 @@ static VALUE parser_new(VALUE self, VALUE mode) {
1238
1195
  * - *:saj*
1239
1196
  * - _cache_keys=_ sets the value of the _cache_keys_ flag.
1240
1197
  * - _cache_keys_ returns the value of the _cache_keys_ flag.
1241
- * - _cache_strings=_ sets the value of the _cache_strings_ to an positive integer less than 35. Strings shorter than that length are cached.
1198
+ * - _cache_strings=_ sets the value of the _cache_strings_ to an positive integer less than 35. Strings shorter than
1199
+ * that length are cached.
1242
1200
  * - _cache_strings_ returns the value of the _cache_strings_ integer value.
1243
1201
  * - _handler=_ sets the SAJ handler
1244
1202
  * - _handler_ returns the SAJ handler
@@ -1246,19 +1204,32 @@ static VALUE parser_new(VALUE self, VALUE mode) {
1246
1204
  * - *:usual*
1247
1205
  * - _cache_keys=_ sets the value of the _cache_keys_ flag.
1248
1206
  * - _cache_keys_ returns the value of the _cache_keys_ flag.
1249
- * - _cache_strings=_ sets the value of the _cache_strings_ to an positive integer less than 35. Strings shorter than that length are cached.
1207
+ * - _cache_strings=_ sets the value of the _cache_strings_ to an positive integer less than 35. Strings shorter than
1208
+ * that length are cached.
1250
1209
  * - _cache_strings_ returns the value of the _cache_strings_ integer value.
1251
- * - _capacity=_ sets the capacity of the parser. The parser grows automatically but can be updated directly with this call.
1210
+ * - _cache_expunge=_ sets the value of the _cache_expunge_ where 0 never expunges, 1 expunges slowly, 2 expunges
1211
+ * faster, and 3 or higher expunges agressively.
1212
+ * - _cache_expunge_ returns the value of the _cache_expunge_ integer value.
1213
+ * - _capacity=_ sets the capacity of the parser. The parser grows automatically but can be updated directly with this
1214
+ * call.
1252
1215
  * - _capacity_ returns the current capacity of the parser's internal stack.
1253
1216
  * - _create_id_ returns the value _create_id_ or _nil_ if there is no _create_id_.
1254
- * - _create_id=_ sets the value _create_id_ or if _nil_ unsets it. Parsed JSON objects that include the specified element use the element value as the name of the class to create an object from instead of a Hash.
1255
- * - _decimal=_ sets the approach to how decimals are parser. If _:auto_ then the decimals with significant digits are 16 or less are Floats and long ones are BigDecimal. _:ruby_ uses a call to Ruby to convert a string to a Float. _:float_ always generates a Float. _:bigdecimal_ always results in a BigDecimal.
1256
- * - _decimal_ returns the value of the decimal conversion option which can be :auto (default), :ruby, :float, or :bigdecimal.
1217
+ * - _create_id=_ sets the value _create_id_ or if _nil_ unsets it. Parsed JSON objects that include the specified
1218
+ * element use the element value as the name of the class to create an object from instead of a Hash.
1219
+ * - _decimal=_ sets the approach to how decimals are parser. If _:auto_ then the decimals with significant digits are
1220
+ * 16 or less are Floats and long ones are BigDecimal. _:ruby_ uses a call to Ruby to convert a string to a Float.
1221
+ * _:float_ always generates a Float. _:bigdecimal_ always results in a BigDecimal.
1222
+ * - _decimal_ returns the value of the decimal conversion option which can be :auto (default), :ruby, :float, or
1223
+ * :bigdecimal.
1257
1224
  * - _ignore_json_create_ returns the value of the _ignore_json_create_ flag.
1258
- * - _ignore_json_create=_ sets the value of the _ignore_json_create_ flag. When set the class json_create method is ignored on parsing in favor of creating an instance and populating directly.
1225
+ * - _ignore_json_create=_ sets the value of the _ignore_json_create_ flag. When set the class json_create method is
1226
+ * ignored on parsing in favor of creating an instance and populating directly.
1259
1227
  * - _missing_class_ return the value of the _missing_class_ indicator.
1260
- * - _missing_class=_ sets the value of the _missing_class_ flag. Valid values are _:auto_ which creates any missing classes on parse, :ignore which ignores and continues as a Hash (default), and :raise which raises an exception if the class is not found.
1261
- * - _omit_null=_ sets the _omit_null_ flag. If true then null values in a map or object are omitted from the resulting Hash or Object.
1228
+ * - _missing_class=_ sets the value of the _missing_class_ flag. Valid values are _:auto_ which creates any missing
1229
+ * classes on parse, :ignore which ignores and continues as a Hash (default), and :raise which raises an exception if
1230
+ * the class is not found.
1231
+ * - _omit_null=_ sets the _omit_null_ flag. If true then null values in a map or object are omitted from the
1232
+ * resulting Hash or Object.
1262
1233
  * - _omit_null_ returns the value of the _omit_null_ flag.
1263
1234
  * - _symbol_keys=_ sets the flag that indicates Hash keys should be parsed to Symbols versus Strings.
1264
1235
  * - _symbol_keys_ returns the value of the _symbol_keys_ flag.
@@ -1427,15 +1398,15 @@ static VALUE usual_parser = Qundef;
1427
1398
  */
1428
1399
  static VALUE parser_usual(VALUE self) {
1429
1400
  if (Qundef == usual_parser) {
1430
- ojParser p = ALLOC(struct _ojParser);
1431
-
1432
- memset(p, 0, sizeof(struct _ojParser));
1433
- buf_init(&p->key);
1434
- buf_init(&p->buf);
1435
- p->map = value_map;
1436
- oj_set_parser_usual(p);
1437
- usual_parser = Data_Wrap_Struct(parser_class, parser_mark, parser_free, p);
1438
- rb_gc_register_address(&usual_parser);
1401
+ ojParser p = ALLOC(struct _ojParser);
1402
+
1403
+ memset(p, 0, sizeof(struct _ojParser));
1404
+ buf_init(&p->key);
1405
+ buf_init(&p->buf);
1406
+ p->map = value_map;
1407
+ oj_set_parser_usual(p);
1408
+ usual_parser = Data_Wrap_Struct(parser_class, parser_mark, parser_free, p);
1409
+ rb_gc_register_address(&usual_parser);
1439
1410
  }
1440
1411
  return usual_parser;
1441
1412
  }
@@ -1450,15 +1421,15 @@ static VALUE saj_parser = Qundef;
1450
1421
  */
1451
1422
  static VALUE parser_saj(VALUE self) {
1452
1423
  if (Qundef == saj_parser) {
1453
- ojParser p = ALLOC(struct _ojParser);
1454
-
1455
- memset(p, 0, sizeof(struct _ojParser));
1456
- buf_init(&p->key);
1457
- buf_init(&p->buf);
1458
- p->map = value_map;
1459
- oj_set_parser_saj(p);
1460
- saj_parser = Data_Wrap_Struct(parser_class, parser_mark, parser_free, p);
1461
- rb_gc_register_address(&saj_parser);
1424
+ ojParser p = ALLOC(struct _ojParser);
1425
+
1426
+ memset(p, 0, sizeof(struct _ojParser));
1427
+ buf_init(&p->key);
1428
+ buf_init(&p->buf);
1429
+ p->map = value_map;
1430
+ oj_set_parser_saj(p);
1431
+ saj_parser = Data_Wrap_Struct(parser_class, parser_mark, parser_free, p);
1432
+ rb_gc_register_address(&saj_parser);
1462
1433
  }
1463
1434
  return saj_parser;
1464
1435
  }
@@ -1472,15 +1443,15 @@ static VALUE validate_parser = Qundef;
1472
1443
  */
1473
1444
  static VALUE parser_validate(VALUE self) {
1474
1445
  if (Qundef == validate_parser) {
1475
- ojParser p = ALLOC(struct _ojParser);
1476
-
1477
- memset(p, 0, sizeof(struct _ojParser));
1478
- buf_init(&p->key);
1479
- buf_init(&p->buf);
1480
- p->map = value_map;
1481
- oj_set_parser_validator(p);
1482
- validate_parser = Data_Wrap_Struct(parser_class, parser_mark, parser_free, p);
1483
- rb_gc_register_address(&validate_parser);
1446
+ ojParser p = ALLOC(struct _ojParser);
1447
+
1448
+ memset(p, 0, sizeof(struct _ojParser));
1449
+ buf_init(&p->key);
1450
+ buf_init(&p->buf);
1451
+ p->map = value_map;
1452
+ oj_set_parser_validator(p);
1453
+ validate_parser = Data_Wrap_Struct(parser_class, parser_mark, parser_free, p);
1454
+ rb_gc_register_address(&validate_parser);
1484
1455
  }
1485
1456
  return validate_parser;
1486
1457
  }
data/ext/oj/saj2.c CHANGED
@@ -158,7 +158,7 @@ static void add_str(ojParser p) {
158
158
  const char * str = buf_str(&p->buf);
159
159
  size_t len = buf_len(&p->buf);
160
160
 
161
- if (d->cache_str <= len) {
161
+ if (d->cache_str < len) {
162
162
  rstr = cache_intern(d->str_cache, str, len);
163
163
  } else {
164
164
  rstr = rb_utf8_str_new(str, len);
@@ -172,7 +172,7 @@ static void add_str_key(ojParser p) {
172
172
  const char * str = buf_str(&p->buf);
173
173
  size_t len = buf_len(&p->buf);
174
174
 
175
- if (d->cache_str <= len) {
175
+ if (d->cache_str < len) {
176
176
  rstr = cache_intern(d->str_cache, str, len);
177
177
  } else {
178
178
  rstr = rb_utf8_str_new(str, len);
@@ -336,7 +336,7 @@ void oj_set_parser_saj(ojParser p) {
336
336
  d->klen = 256;
337
337
  d->keys = ALLOC_N(VALUE, d->klen);
338
338
  d->tail = d->keys;
339
- d->str_cache = cache_create(0, form_str, true);
339
+ d->str_cache = cache_create(0, form_str, true, false);
340
340
 
341
341
  p->ctx = (void *)d;
342
342
  reset(p);
data/ext/oj/strict.c CHANGED
@@ -37,8 +37,8 @@ VALUE oj_calc_hash_key(ParseInfo pi, Val parent) {
37
37
  } else {
38
38
  rkey = rb_str_new(parent->key, parent->klen);
39
39
  rkey = oj_encode(rkey);
40
+ OBJ_FREEZE(rkey);
40
41
  }
41
- OBJ_FREEZE(rkey);
42
42
  return rkey;
43
43
  }
44
44
  if (Yes == pi->options.sym_key) {
@@ -46,7 +46,6 @@ VALUE oj_calc_hash_key(ParseInfo pi, Val parent) {
46
46
  } else {
47
47
  rkey = oj_str_intern(parent->key, parent->klen);
48
48
  }
49
- OBJ_FREEZE(rkey);
50
49
  return rkey;
51
50
  }
52
51
 
data/ext/oj/usual.c CHANGED
@@ -77,6 +77,7 @@ typedef struct _delegate {
77
77
  char * create_id;
78
78
  uint8_t create_id_len;
79
79
  uint8_t cache_str;
80
+ uint8_t cache_xrate;
80
81
  uint8_t miss_class;
81
82
  bool cache_keys;
82
83
  bool ignore_json_create;
@@ -100,7 +101,6 @@ static VALUE form_str(const char *str, size_t len) {
100
101
  }
101
102
 
102
103
  static VALUE form_sym(const char *str, size_t len) {
103
- // return ID2SYM(rb_intern3(str, len, oj_utf8_encoding));
104
104
  return rb_str_intern(rb_utf8_str_new(str, len));
105
105
  }
106
106
 
@@ -323,7 +323,7 @@ static void open_array_key(ojParser p) {
323
323
  }
324
324
 
325
325
  static void close_object(ojParser p) {
326
- VALUE *vp;
326
+ VALUE * vp;
327
327
  Delegate d = (Delegate)p->ctx;
328
328
 
329
329
  d->ctail--;
@@ -356,7 +356,7 @@ static void close_object(ojParser p) {
356
356
  }
357
357
 
358
358
  static void close_object_class(ojParser p) {
359
- VALUE *vp;
359
+ VALUE * vp;
360
360
  Delegate d = (Delegate)p->ctx;
361
361
 
362
362
  d->ctail--;
@@ -379,7 +379,7 @@ static void close_object_class(ojParser p) {
379
379
  }
380
380
 
381
381
  static void close_object_create(ojParser p) {
382
- VALUE *vp;
382
+ VALUE * vp;
383
383
  Delegate d = (Delegate)p->ctx;
384
384
 
385
385
  d->ctail--;
@@ -471,7 +471,7 @@ static void close_array(ojParser p) {
471
471
  }
472
472
 
473
473
  static void close_array_class(ojParser p) {
474
- VALUE *vp;
474
+ VALUE * vp;
475
475
  Delegate d = (Delegate)p->ctx;
476
476
 
477
477
  d->ctail--;
@@ -686,10 +686,10 @@ static void mark(ojParser p) {
686
686
  return;
687
687
  }
688
688
  Delegate d = (Delegate)p->ctx;
689
- VALUE *vp;
689
+ VALUE * vp;
690
690
 
691
691
  if (NULL == d) {
692
- return;
692
+ return;
693
693
  }
694
694
  cache_mark(d->str_cache);
695
695
  if (NULL != d->sym_cache) {
@@ -792,6 +792,30 @@ static VALUE opt_cache_strings_set(ojParser p, VALUE value) {
792
792
  return INT2NUM((int)d->cache_str);
793
793
  }
794
794
 
795
+ static VALUE opt_cache_expunge(ojParser p, VALUE value) {
796
+ Delegate d = (Delegate)p->ctx;
797
+
798
+ return INT2NUM((int)d->cache_xrate);
799
+ }
800
+
801
+ static VALUE opt_cache_expunge_set(ojParser p, VALUE value) {
802
+ Delegate d = (Delegate)p->ctx;
803
+ int rate = NUM2INT(value);
804
+
805
+ if (rate < 0) {
806
+ rate = 0;
807
+ } else if (3 < rate) {
808
+ rate = 3;
809
+ }
810
+ d->cache_xrate = (uint8_t)rate;
811
+ cache_set_expunge_rate(d->str_cache, rate);
812
+ cache_set_expunge_rate(d->attr_cache, rate);
813
+ if (NULL != d->sym_cache) {
814
+ cache_set_expunge_rate(d->sym_cache, rate);
815
+ }
816
+ return INT2NUM((int)rate);
817
+ }
818
+
795
819
  static VALUE opt_capacity(ojParser p, VALUE value) {
796
820
  Delegate d = (Delegate)p->ctx;
797
821
 
@@ -830,11 +854,7 @@ static VALUE opt_class_cache_set(ojParser p, VALUE value) {
830
854
 
831
855
  if (Qtrue == value) {
832
856
  if (NULL == d->class_cache) {
833
- if (MISS_AUTO == d->miss_class) {
834
- d->class_cache = cache_create(0, form_class_auto, true);
835
- } else {
836
- d->class_cache = cache_create(0, form_class, false);
837
- }
857
+ d->class_cache = cache_create(0, form_class_auto, MISS_AUTO == d->miss_class, false);
838
858
  }
839
859
  } else if (NULL != d->class_cache) {
840
860
  cache_free(d->class_cache);
@@ -1078,7 +1098,8 @@ static VALUE opt_symbol_keys_set(ojParser p, VALUE value) {
1078
1098
  Delegate d = (Delegate)p->ctx;
1079
1099
 
1080
1100
  if (Qtrue == value) {
1081
- d->sym_cache = cache_create(0, form_sym, true);
1101
+ d->sym_cache = cache_create(0, form_sym, true, false);
1102
+ cache_set_expunge_rate(d->sym_cache, d->cache_xrate);
1082
1103
  d->key_cache = d->sym_cache;
1083
1104
  if (!d->cache_keys) {
1084
1105
  d->get_key = sym_key;
@@ -1097,13 +1118,15 @@ static VALUE opt_symbol_keys_set(ojParser p, VALUE value) {
1097
1118
 
1098
1119
  static VALUE option(ojParser p, const char *key, VALUE value) {
1099
1120
  struct opt *op;
1100
- struct opt opts[] = {
1121
+ struct opt opts[] = {
1101
1122
  {.name = "array_class", .func = opt_array_class},
1102
1123
  {.name = "array_class=", .func = opt_array_class_set},
1103
1124
  {.name = "cache_keys", .func = opt_cache_keys},
1104
1125
  {.name = "cache_keys=", .func = opt_cache_keys_set},
1105
1126
  {.name = "cache_strings", .func = opt_cache_strings},
1106
1127
  {.name = "cache_strings=", .func = opt_cache_strings_set},
1128
+ {.name = "cache_expunge", .func = opt_cache_expunge},
1129
+ {.name = "cache_expunge=", .func = opt_cache_expunge_set},
1107
1130
  {.name = "capacity", .func = opt_capacity},
1108
1131
  {.name = "capacity=", .func = opt_capacity_set},
1109
1132
  {.name = "class_cache", .func = opt_class_cache},
@@ -1163,6 +1186,7 @@ void oj_set_parser_usual(ojParser p) {
1163
1186
  d->create_id = NULL;
1164
1187
  d->create_id_len = 0;
1165
1188
  d->miss_class = MISS_IGNORE;
1189
+ d->cache_xrate = 1;
1166
1190
 
1167
1191
  Funcs f = &p->funcs[TOP_FUN];
1168
1192
  f->add_null = add_null;
@@ -1203,8 +1227,8 @@ void oj_set_parser_usual(ojParser p) {
1203
1227
  f->open_object = open_object_key;
1204
1228
  f->close_object = close_object;
1205
1229
 
1206
- d->str_cache = cache_create(0, form_str, true);
1207
- d->attr_cache = cache_create(0, form_attr, false);
1230
+ d->str_cache = cache_create(0, form_str, true, false);
1231
+ d->attr_cache = cache_create(0, form_attr, false, false);
1208
1232
  d->sym_cache = NULL;
1209
1233
  d->class_cache = NULL;
1210
1234
  d->key_cache = d->str_cache;