@@ -2302,6 +2302,26 @@ static inline VALUE build_string(const char *start, const char *end, bool intern
2302
2302
return result ;
2303
2303
}
2304
2304
2305
+ static VALUE json_string_fastpath (JSON_Parser * json , char * string , char * stringEnd , bool is_name , bool intern , bool symbolize )
2306
+ {
2307
+ size_t bufferSize = stringEnd - string ;
2308
+
2309
+ if (is_name ) {
2310
+ VALUE cached_key ;
2311
+ if (RB_UNLIKELY (symbolize )) {
2312
+ cached_key = rsymbol_cache_fetch (& json -> name_cache , string , bufferSize );
2313
+ } else {
2314
+ cached_key = rstring_cache_fetch (& json -> name_cache , string , bufferSize );
2315
+ }
2316
+
2317
+ if (RB_LIKELY (cached_key )) {
2318
+ return cached_key ;
2319
+ }
2320
+ }
2321
+
2322
+ return build_string (string , stringEnd , intern , symbolize );
2323
+ }
2324
+
2305
2325
static VALUE json_string_unescape (JSON_Parser * json , char * string , char * stringEnd , bool is_name , bool intern , bool symbolize )
2306
2326
{
2307
2327
size_t bufferSize = stringEnd - string ;
@@ -2323,7 +2343,7 @@ static VALUE json_string_unescape(JSON_Parser *json, char *string, char *stringE
2323
2343
}
2324
2344
2325
2345
pe = memchr (p , '\\' , bufferSize );
2326
- if (RB_LIKELY (pe == NULL )) {
2346
+ if (RB_UNLIKELY (pe == NULL )) {
2327
2347
return build_string (string , stringEnd , intern , symbolize );
2328
2348
}
2329
2349
@@ -2424,15 +2444,15 @@ static VALUE json_string_unescape(JSON_Parser *json, char *string, char *stringE
2424
2444
}
2425
2445
2426
2446
2427
- #line 2428 "parser.c"
2447
+ #line 2448 "parser.c"
2428
2448
enum {JSON_string_start = 1 };
2429
- enum {JSON_string_first_final = 8 };
2449
+ enum {JSON_string_first_final = 9 };
2430
2450
enum {JSON_string_error = 0 };
2431
2451
2432
2452
enum {JSON_string_en_main = 1 };
2433
2453
2434
2454
2435
- #line 1019 "parser.rl"
2455
+ #line 1051 "parser.rl"
2436
2456
2437
2457
2438
2458
static int
@@ -2453,15 +2473,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
2453
2473
VALUE match_string ;
2454
2474
2455
2475
2456
- #line 2457 "parser.c"
2476
+ #line 2477 "parser.c"
2457
2477
{
2458
2478
cs = JSON_string_start ;
2459
2479
}
2460
2480
2461
- #line 1039 "parser.rl"
2481
+ #line 1071 "parser.rl"
2462
2482
json -> memo = p ;
2463
2483
2464
- #line 2465 "parser.c"
2484
+ #line 2485 "parser.c"
2465
2485
{
2466
2486
if ( p == pe )
2467
2487
goto _test_eof ;
@@ -2486,47 +2506,56 @@ case 2:
2486
2506
goto st0 ;
2487
2507
goto st2 ;
2488
2508
tr2 :
2489
- #line 1006 "parser.rl"
2509
+ #line 1033 "parser.rl"
2510
+ {
2511
+ * result = json_string_fastpath (json , json -> memo + 1 , p , json -> parsing_name , json -> parsing_name || json -> freeze , json -> parsing_name && json -> symbolize_names );
2512
+ {p = (( p + 1 ))- 1 ;}
2513
+ p -- ;
2514
+ {p ++ ; cs = 9 ; goto _out ;}
2515
+ }
2516
+ #line 1026 "parser.rl"
2490
2517
{
2491
2518
* result = json_string_unescape (json , json -> memo + 1 , p , json -> parsing_name , json -> parsing_name || json -> freeze , json -> parsing_name && json -> symbolize_names );
2492
- if (NIL_P (* result )) {
2493
- p -- ;
2494
- {p ++ ; cs = 8 ; goto _out ;}
2495
- } else {
2496
- {p = (( p + 1 ))- 1 ;}
2497
- }
2519
+ {p = (( p + 1 ))- 1 ;}
2520
+ p -- ;
2521
+ {p ++ ; cs = 9 ; goto _out ;}
2498
2522
}
2499
- #line 1016 "parser.rl"
2500
- { p -- ; {p ++ ; cs = 8 ; goto _out ;} }
2501
- goto st8 ;
2502
- st8 :
2523
+ goto st9 ;
2524
+ tr6 :
2525
+ #line 1026 "parser.rl"
2526
+ {
2527
+ * result = json_string_unescape (json , json -> memo + 1 , p , json -> parsing_name , json -> parsing_name || json -> freeze , json -> parsing_name && json -> symbolize_names );
2528
+ {p = (( p + 1 ))- 1 ;}
2529
+ p -- ;
2530
+ {p ++ ; cs = 9 ; goto _out ;}
2531
+ }
2532
+ goto st9 ;
2533
+ st9 :
2503
2534
if ( ++ p == pe )
2504
- goto _test_eof8 ;
2505
- case 8 :
2506
- #line 2507 "parser.c"
2535
+ goto _test_eof9 ;
2536
+ case 9 :
2537
+ #line 2538 "parser.c"
2507
2538
goto st0 ;
2508
2539
st3 :
2509
2540
if ( ++ p == pe )
2510
2541
goto _test_eof3 ;
2511
2542
case 3 :
2512
2543
if ( (* p ) == 117 )
2513
- goto st4 ;
2544
+ goto st5 ;
2514
2545
if ( 0 <= (signed char )(* (p )) && (* (p )) <= 31 )
2515
2546
goto st0 ;
2516
- goto st2 ;
2547
+ goto st4 ;
2517
2548
st4 :
2518
2549
if ( ++ p == pe )
2519
2550
goto _test_eof4 ;
2520
2551
case 4 :
2521
- if ( (* p ) < 65 ) {
2522
- if ( 48 <= (* p ) && (* p ) <= 57 )
2523
- goto st5 ;
2524
- } else if ( (* p ) > 70 ) {
2525
- if ( 97 <= (* p ) && (* p ) <= 102 )
2526
- goto st5 ;
2527
- } else
2528
- goto st5 ;
2529
- goto st0 ;
2552
+ switch ( (* p ) ) {
2553
+ case 34 : goto tr6 ;
2554
+ case 92 : goto st3 ;
2555
+ }
2556
+ if ( 0 <= (signed char )(* (p )) && (* (p )) <= 31 )
2557
+ goto st0 ;
2558
+ goto st4 ;
2530
2559
st5 :
2531
2560
if ( ++ p == pe )
2532
2561
goto _test_eof5 ;
@@ -2559,27 +2588,41 @@ case 6:
2559
2588
case 7 :
2560
2589
if ( (* p ) < 65 ) {
2561
2590
if ( 48 <= (* p ) && (* p ) <= 57 )
2562
- goto st2 ;
2591
+ goto st8 ;
2592
+ } else if ( (* p ) > 70 ) {
2593
+ if ( 97 <= (* p ) && (* p ) <= 102 )
2594
+ goto st8 ;
2595
+ } else
2596
+ goto st8 ;
2597
+ goto st0 ;
2598
+ st8 :
2599
+ if ( ++ p == pe )
2600
+ goto _test_eof8 ;
2601
+ case 8 :
2602
+ if ( (* p ) < 65 ) {
2603
+ if ( 48 <= (* p ) && (* p ) <= 57 )
2604
+ goto st4 ;
2563
2605
} else if ( (* p ) > 70 ) {
2564
2606
if ( 97 <= (* p ) && (* p ) <= 102 )
2565
- goto st2 ;
2607
+ goto st4 ;
2566
2608
} else
2567
- goto st2 ;
2609
+ goto st4 ;
2568
2610
goto st0 ;
2569
2611
}
2570
2612
_test_eof2 : cs = 2 ; goto _test_eof ;
2571
- _test_eof8 : cs = 8 ; goto _test_eof ;
2613
+ _test_eof9 : cs = 9 ; goto _test_eof ;
2572
2614
_test_eof3 : cs = 3 ; goto _test_eof ;
2573
2615
_test_eof4 : cs = 4 ; goto _test_eof ;
2574
2616
_test_eof5 : cs = 5 ; goto _test_eof ;
2575
2617
_test_eof6 : cs = 6 ; goto _test_eof ;
2576
2618
_test_eof7 : cs = 7 ; goto _test_eof ;
2619
+ _test_eof8 : cs = 8 ; goto _test_eof ;
2577
2620
2578
2621
_test_eof : {}
2579
2622
_out : {}
2580
2623
}
2581
2624
2582
- #line 1041 "parser.rl"
2625
+ #line 1073 "parser.rl"
2583
2626
2584
2627
if (json -> create_additions && RTEST (match_string = json -> match_string )) {
2585
2628
VALUE klass ;
@@ -2732,15 +2775,15 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
2732
2775
}
2733
2776
2734
2777
2735
- #line 2736 "parser.c"
2778
+ #line 2779 "parser.c"
2736
2779
enum {JSON_start = 1 };
2737
2780
enum {JSON_first_final = 10 };
2738
2781
enum {JSON_error = 0 };
2739
2782
2740
2783
enum {JSON_en_main = 1 };
2741
2784
2742
2785
2743
- #line 1207 "parser.rl"
2786
+ #line 1239 "parser.rl"
2744
2787
2745
2788
2746
2789
/*
@@ -2769,16 +2812,16 @@ static VALUE cParser_parse(VALUE self)
2769
2812
json -> stack = & stack ;
2770
2813
2771
2814
2772
- #line 2773 "parser.c"
2815
+ #line 2816 "parser.c"
2773
2816
{
2774
2817
cs = JSON_start ;
2775
2818
}
2776
2819
2777
- #line 1235 "parser.rl"
2820
+ #line 1267 "parser.rl"
2778
2821
p = json -> source ;
2779
2822
pe = p + json -> len ;
2780
2823
2781
- #line 2782 "parser.c"
2824
+ #line 2825 "parser.c"
2782
2825
{
2783
2826
if ( p == pe )
2784
2827
goto _test_eof ;
@@ -2812,7 +2855,7 @@ case 1:
2812
2855
cs = 0 ;
2813
2856
goto _out ;
2814
2857
tr2 :
2815
- #line 1199 "parser.rl"
2858
+ #line 1231 "parser.rl"
2816
2859
{
2817
2860
char * np = JSON_parse_value (json , p , pe , & result , 0 );
2818
2861
if (np == NULL ) { p -- ; {p ++ ; cs = 10 ; goto _out ;} } else {p = (( np ))- 1 ;}
@@ -2822,7 +2865,7 @@ cs = 0;
2822
2865
if ( ++ p == pe )
2823
2866
goto _test_eof10 ;
2824
2867
case 10 :
2825
- #line 2826 "parser.c"
2868
+ #line 2869 "parser.c"
2826
2869
switch ( (* p ) ) {
2827
2870
case 13 : goto st10 ;
2828
2871
case 32 : goto st10 ;
@@ -2911,7 +2954,7 @@ case 9:
2911
2954
_out : {}
2912
2955
}
2913
2956
2914
- #line 1238 "parser.rl"
2957
+ #line 1270 "parser.rl"
2915
2958
2916
2959
if (json -> stack_handle ) {
2917
2960
rvalue_stack_eagerly_release (json -> stack_handle );
@@ -2947,16 +2990,16 @@ static VALUE cParser_m_parse(VALUE klass, VALUE source, VALUE opts)
2947
2990
json -> stack = & stack ;
2948
2991
2949
2992
2950
- #line 2951 "parser.c"
2993
+ #line 2994 "parser.c"
2951
2994
{
2952
2995
cs = JSON_start ;
2953
2996
}
2954
2997
2955
- #line 1273 "parser.rl"
2998
+ #line 1305 "parser.rl"
2956
2999
p = json -> source ;
2957
3000
pe = p + json -> len ;
2958
3001
2959
- #line 2960 "parser.c"
3002
+ #line 3003 "parser.c"
2960
3003
{
2961
3004
if ( p == pe )
2962
3005
goto _test_eof ;
@@ -2990,7 +3033,7 @@ case 1:
2990
3033
cs = 0 ;
2991
3034
goto _out ;
2992
3035
tr2 :
2993
- #line 1199 "parser.rl"
3036
+ #line 1231 "parser.rl"
2994
3037
{
2995
3038
char * np = JSON_parse_value (json , p , pe , & result , 0 );
2996
3039
if (np == NULL ) { p -- ; {p ++ ; cs = 10 ; goto _out ;} } else {p = (( np ))- 1 ;}
@@ -3000,7 +3043,7 @@ cs = 0;
3000
3043
if ( ++ p == pe )
3001
3044
goto _test_eof10 ;
3002
3045
case 10 :
3003
- #line 3004 "parser.c"
3046
+ #line 3047 "parser.c"
3004
3047
switch ( (* p ) ) {
3005
3048
case 13 : goto st10 ;
3006
3049
case 32 : goto st10 ;
@@ -3089,7 +3132,7 @@ case 9:
3089
3132
_out : {}
3090
3133
}
3091
3134
3092
- #line 1276 "parser.rl"
3135
+ #line 1308 "parser.rl"
3093
3136
3094
3137
if (json -> stack_handle ) {
3095
3138
rvalue_stack_eagerly_release (json -> stack_handle );
0 commit comments