@@ -642,20 +642,16 @@ json_object_i(VALUE key, VALUE val, VALUE _arg)
642
642
JSON_Generator_State * state = arg -> state ;
643
643
VALUE Vstate = arg -> Vstate ;
644
644
645
- char * object_nl = state -> object_nl ;
646
- long object_nl_len = state -> object_nl_len ;
647
- char * indent = state -> indent ;
648
- long indent_len = state -> indent_len ;
649
645
long depth = state -> depth ;
650
646
int j ;
651
647
652
648
if (arg -> iter > 0 ) fbuffer_append_char (buffer , ',' );
653
- if (object_nl ) {
654
- fbuffer_append (buffer , object_nl , object_nl_len );
649
+ if (RB_UNLIKELY ( state -> object_nl ) ) {
650
+ fbuffer_append (buffer , state -> object_nl , state -> object_nl_len );
655
651
}
656
- if (indent ) {
652
+ if (RB_UNLIKELY ( state -> indent ) ) {
657
653
for (j = 0 ; j < depth ; j ++ ) {
658
- fbuffer_append (buffer , indent , indent_len );
654
+ fbuffer_append (buffer , state -> indent , state -> indent_len );
659
655
}
660
656
}
661
657
@@ -684,10 +680,6 @@ json_object_i(VALUE key, VALUE val, VALUE _arg)
684
680
685
681
static void generate_json_object (FBuffer * buffer , VALUE Vstate , JSON_Generator_State * state , VALUE obj )
686
682
{
687
- char * object_nl = state -> object_nl ;
688
- long object_nl_len = state -> object_nl_len ;
689
- char * indent = state -> indent ;
690
- long indent_len = state -> indent_len ;
691
683
long max_nesting = state -> max_nesting ;
692
684
long depth = ++ state -> depth ;
693
685
int j ;
@@ -705,11 +697,11 @@ static void generate_json_object(FBuffer *buffer, VALUE Vstate, JSON_Generator_S
705
697
rb_hash_foreach (obj , json_object_i , (VALUE )& arg );
706
698
707
699
depth = -- state -> depth ;
708
- if (object_nl ) {
709
- fbuffer_append (buffer , object_nl , object_nl_len );
710
- if (indent ) {
700
+ if (RB_UNLIKELY ( state -> object_nl ) ) {
701
+ fbuffer_append (buffer , state -> object_nl , state -> object_nl_len );
702
+ if (RB_UNLIKELY ( state -> indent ) ) {
711
703
for (j = 0 ; j < depth ; j ++ ) {
712
- fbuffer_append (buffer , indent , indent_len );
704
+ fbuffer_append (buffer , state -> indent , state -> indent_len );
713
705
}
714
706
}
715
707
}
@@ -718,36 +710,32 @@ static void generate_json_object(FBuffer *buffer, VALUE Vstate, JSON_Generator_S
718
710
719
711
static void generate_json_array (FBuffer * buffer , VALUE Vstate , JSON_Generator_State * state , VALUE obj )
720
712
{
721
- char * array_nl = state -> array_nl ;
722
- long array_nl_len = state -> array_nl_len ;
723
- char * indent = state -> indent ;
724
- long indent_len = state -> indent_len ;
725
713
long max_nesting = state -> max_nesting ;
726
714
long depth = ++ state -> depth ;
727
715
int i , j ;
728
716
if (max_nesting != 0 && depth > max_nesting ) {
729
717
rb_raise (eNestingError , "nesting of %ld is too deep" , -- state -> depth );
730
718
}
731
719
fbuffer_append_char (buffer , '[' );
732
- if (array_nl ) fbuffer_append (buffer , array_nl , array_nl_len );
720
+ if (RB_UNLIKELY ( state -> array_nl )) fbuffer_append (buffer , state -> array_nl , state -> array_nl_len );
733
721
for (i = 0 ; i < RARRAY_LEN (obj ); i ++ ) {
734
722
if (i > 0 ) {
735
723
fbuffer_append_char (buffer , ',' );
736
724
if (RB_UNLIKELY (state -> array_nl )) fbuffer_append (buffer , state -> array_nl , state -> array_nl_len );
737
725
}
738
- if (indent ) {
726
+ if (RB_UNLIKELY ( state -> indent ) ) {
739
727
for (j = 0 ; j < depth ; j ++ ) {
740
- fbuffer_append (buffer , indent , indent_len );
728
+ fbuffer_append (buffer , state -> indent , state -> indent_len );
741
729
}
742
730
}
743
731
generate_json (buffer , Vstate , state , RARRAY_AREF (obj , i ));
744
732
}
745
733
state -> depth = -- depth ;
746
- if (array_nl ) {
747
- fbuffer_append (buffer , array_nl , array_nl_len );
748
- if (indent ) {
734
+ if (RB_UNLIKELY ( state -> array_nl ) ) {
735
+ fbuffer_append (buffer , state -> array_nl , state -> array_nl_len );
736
+ if (RB_UNLIKELY ( state -> indent ) ) {
749
737
for (j = 0 ; j < depth ; j ++ ) {
750
- fbuffer_append (buffer , indent , indent_len );
738
+ fbuffer_append (buffer , state -> indent , state -> indent_len );
751
739
}
752
740
}
753
741
}
0 commit comments