Skip to content

Commit de6e59e

Browse files
committed
Sync ruby/json
Fix: ruby/json#796
1 parent e8ad728 commit de6e59e

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

ext/json/generator/extconf.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
return 0;
1919
}
2020
SRC
21-
$defs.push("-DENABLE_SIMD")
21+
$defs.push("-DJSON_ENABLE_SIMD")
2222
end
2323
end
2424

@@ -29,7 +29,7 @@
2929
return 0;
3030
}
3131
SRC
32-
$defs.push("-DENABLE_SIMD")
32+
$defs.push("-DJSON_ENABLE_SIMD")
3333
end
3434

3535
have_header('cpuid.h')

ext/json/generator/generator.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ typedef struct _search_state {
112112
const char *cursor;
113113
FBuffer *buffer;
114114

115-
#ifdef ENABLE_SIMD
115+
#ifdef HAVE_SIMD
116116
const char *chunk_base;
117117
const char *chunk_end;
118118
bool has_matches;
@@ -124,7 +124,7 @@ typedef struct _search_state {
124124
#else
125125
#error "Unknown SIMD Implementation."
126126
#endif /* HAVE_SIMD_NEON */
127-
#endif /* ENABLE_SIMD */
127+
#endif /* HAVE_SIMD */
128128
} search_state;
129129

130130
#if (defined(__GNUC__ ) || defined(__clang__))
@@ -189,15 +189,11 @@ static inline FORCE_INLINE void escape_UTF8_char_basic(search_state *search)
189189
case '\r': fbuffer_append(search->buffer, "\\r", 2); break;
190190
case '\t': fbuffer_append(search->buffer, "\\t", 2); break;
191191
default: {
192-
if (ch < ' ') {
193-
const char *hexdig = "0123456789abcdef";
194-
char scratch[6] = { '\\', 'u', '0', '0', 0, 0 };
195-
scratch[4] = hexdig[(ch >> 4) & 0xf];
196-
scratch[5] = hexdig[ch & 0xf];
197-
fbuffer_append(search->buffer, scratch, 6);
198-
} else {
199-
fbuffer_append_char(search->buffer, ch);
200-
}
192+
const char *hexdig = "0123456789abcdef";
193+
char scratch[6] = { '\\', 'u', '0', '0', 0, 0 };
194+
scratch[4] = hexdig[(ch >> 4) & 0xf];
195+
scratch[5] = hexdig[ch & 0xf];
196+
fbuffer_append(search->buffer, scratch, 6);
201197
break;
202198
}
203199
}
@@ -265,7 +261,7 @@ static inline void escape_UTF8_char(search_state *search, unsigned char ch_len)
265261
search->cursor = (search->ptr += ch_len);
266262
}
267263

268-
#ifdef ENABLE_SIMD
264+
#ifdef HAVE_SIMD
269265

270266
static inline FORCE_INLINE char *copy_remaining_bytes(search_state *search, unsigned long vec_len, unsigned long len)
271267
{
@@ -537,7 +533,7 @@ static inline TARGET_SSE2 FORCE_INLINE unsigned char search_escape_basic_sse2(se
537533

538534
#endif /* HAVE_SIMD_SSE2 */
539535

540-
#endif /* ENABLE_SIMD */
536+
#endif /* HAVE_SIMD */
541537

542538
static const unsigned char script_safe_escape_table[256] = {
543539
// ASCII Control Characters
@@ -1302,11 +1298,11 @@ static void generate_json_string(FBuffer *buffer, struct generate_json_data *dat
13021298
search.cursor = search.ptr;
13031299
search.end = search.ptr + len;
13041300

1305-
#ifdef ENABLE_SIMD
1301+
#ifdef HAVE_SIMD
13061302
search.matches_mask = 0;
13071303
search.has_matches = false;
13081304
search.chunk_base = NULL;
1309-
#endif /* ENABLE_SIMD */
1305+
#endif /* HAVE_SIMD */
13101306

13111307
switch(rb_enc_str_coderange(obj)) {
13121308
case ENC_CODERANGE_7BIT:
@@ -2174,7 +2170,7 @@ void Init_generator(void)
21742170

21752171

21762172
switch(find_simd_implementation()) {
2177-
#ifdef ENABLE_SIMD
2173+
#ifdef HAVE_SIMD
21782174
#ifdef HAVE_SIMD_NEON
21792175
case SIMD_NEON:
21802176
search_escape_basic_impl = search_escape_basic_neon;
@@ -2185,7 +2181,7 @@ void Init_generator(void)
21852181
search_escape_basic_impl = search_escape_basic_sse2;
21862182
break;
21872183
#endif /* HAVE_SIMD_SSE2 */
2188-
#endif /* ENABLE_SIMD */
2184+
#endif /* HAVE_SIMD */
21892185
default:
21902186
search_escape_basic_impl = search_escape_basic;
21912187
break;

ext/json/generator/simd.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ typedef enum {
44
SIMD_SSE2
55
} SIMD_Implementation;
66

7-
#ifdef ENABLE_SIMD
7+
#ifdef JSON_ENABLE_SIMD
88

99
#ifdef __clang__
1010
#if __has_builtin(__builtin_ctzll)
@@ -56,6 +56,7 @@ static SIMD_Implementation find_simd_implementation(void) {
5656
return SIMD_NEON;
5757
}
5858

59+
#define HAVE_SIMD 1
5960
#define HAVE_SIMD_NEON 1
6061

6162
uint8x16x4_t load_uint8x16_4(const unsigned char *table) {
@@ -74,6 +75,7 @@ uint8x16x4_t load_uint8x16_4(const unsigned char *table) {
7475
#ifdef HAVE_X86INTRIN_H
7576
#include <x86intrin.h>
7677

78+
#define HAVE_SIMD 1
7779
#define HAVE_SIMD_SSE2 1
7880

7981
#ifdef HAVE_CPUID_H
@@ -101,7 +103,7 @@ static SIMD_Implementation find_simd_implementation(void) {
101103
#endif /* HAVE_X86INTRIN_H */
102104
#endif /* X86_64 Support */
103105

104-
#endif /* ENABLE_SIMD */
106+
#endif /* JSON_ENABLE_SIMD */
105107

106108
#ifndef FIND_SIMD_IMPLEMENTATION_DEFINED
107109
static SIMD_Implementation find_simd_implementation(void) {

0 commit comments

Comments
 (0)