@@ -78,17 +78,51 @@ static void rvalue_cache_insert_at(rvalue_cache *cache, int index, VALUE rstring
7878 cache -> entries [index ] = rstring ;
7979}
8080
81- static inline int rstring_cache_cmp (const char * str , const long length , VALUE rstring )
81+ static ALWAYS_INLINE () int rstring_cache_cmp (const char * str , const long length , VALUE rstring )
8282{
83+ #if defined(__BYTE_ORDER__ ) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ) && defined(__has_builtin ) && __has_builtin (__builtin_bswap64 )
84+ const char * rptr ;
85+ long rstring_length ;
86+
87+ RSTRING_GETMEM (rstring , rptr , rstring_length );
88+
89+ if (length != rstring_length ) {
90+ return (int )(length - rstring_length );
91+ }
92+
93+ long i = 0 ;
94+
95+ for (; i + 8 <= length ; i += 8 ) {
96+ uint64_t a , b ;
97+ memcpy (& a , str + i , 8 );
98+ memcpy (& b , rptr + i , 8 );
99+ if (a != b ) {
100+ a = __builtin_bswap64 (a );
101+ b = __builtin_bswap64 (b );
102+ return (a < b ) ? -1 : 1 ;
103+ }
104+ }
105+
106+ for (; i < length ; i ++ ) {
107+ unsigned char ca = (unsigned char )str [i ];
108+ unsigned char cb = (unsigned char )rptr [i ];
109+ if (ca != cb ) {
110+ return (ca < cb ) ? -1 : 1 ;
111+ }
112+ }
113+
114+ return 0 ;
115+ #else
83116 long rstring_length = RSTRING_LEN (rstring );
84117 if (length == rstring_length ) {
85118 return memcmp (str , RSTRING_PTR (rstring ), length );
86119 } else {
87120 return (int )(length - rstring_length );
88121 }
122+ #endif
89123}
90124
91- static VALUE rstring_cache_fetch (rvalue_cache * cache , const char * str , const long length )
125+ static ALWAYS_INLINE () VALUE rstring_cache_fetch (rvalue_cache * cache , const char * str , const long length )
92126{
93127 if (RB_UNLIKELY (length > JSON_RVALUE_CACHE_MAX_ENTRY_LENGTH )) {
94128 // Common names aren't likely to be very long. So we just don't
@@ -533,7 +567,7 @@ json_eat_comments(JSON_ParserState *state)
533567 }
534568}
535569
536- static inline void
570+ static ALWAYS_INLINE () void
537571json_eat_whitespace (JSON_ParserState * state )
538572{
539573 while (true ) {
0 commit comments