[ruby/json] Improve consistency of code style

a497c71960
This commit is contained in:
Jean Boussier 2025-07-05 09:10:41 +02:00 committed by Hiroshi SHIBATA
parent e1d09ffe5d
commit d0fdbef4ea
3 changed files with 23 additions and 15 deletions

View file

@ -586,7 +586,8 @@ static inline unsigned char search_ascii_only_escape(search_state *search, const
return 0; return 0;
} }
static inline void full_escape_UTF8_char(search_state *search, unsigned char ch_len) { static inline void full_escape_UTF8_char(search_state *search, unsigned char ch_len)
{
const unsigned char ch = (unsigned char)*search->ptr; const unsigned char ch = (unsigned char)*search->ptr;
switch (ch_len) { switch (ch_len) {
case 1: { case 1: {
@ -616,7 +617,7 @@ static inline void full_escape_UTF8_char(search_state *search, unsigned char ch_
uint32_t wchar = 0; uint32_t wchar = 0;
switch(ch_len) { switch (ch_len) {
case 2: case 2:
wchar = ch & 0x1F; wchar = ch & 0x1F;
break; break;
@ -776,7 +777,8 @@ static VALUE mHash_to_json(int argc, VALUE *argv, VALUE self)
* _state_ is a JSON::State object, that can also be used to configure the * _state_ is a JSON::State object, that can also be used to configure the
* produced JSON string output further. * produced JSON string output further.
*/ */
static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self) { static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self)
{
rb_check_arity(argc, 0, 1); rb_check_arity(argc, 0, 1);
VALUE Vstate = cState_from_state_s(cState, argc == 1 ? argv[0] : Qnil); VALUE Vstate = cState_from_state_s(cState, argc == 1 ? argv[0] : Qnil);
return cState_partial_generate(Vstate, self, generate_json_array, Qfalse); return cState_partial_generate(Vstate, self, generate_json_array, Qfalse);
@ -838,7 +840,8 @@ static VALUE mFloat_to_json(int argc, VALUE *argv, VALUE self)
* *
* Extends _modul_ with the String::Extend module. * Extends _modul_ with the String::Extend module.
*/ */
static VALUE mString_included_s(VALUE self, VALUE modul) { static VALUE mString_included_s(VALUE self, VALUE modul)
{
VALUE result = rb_funcall(modul, i_extend, 1, mString_Extend); VALUE result = rb_funcall(modul, i_extend, 1, mString_Extend);
rb_call_super(1, &modul); rb_call_super(1, &modul);
return result; return result;
@ -1083,7 +1086,7 @@ json_object_i(VALUE key, VALUE val, VALUE _arg)
} }
VALUE key_to_s; VALUE key_to_s;
switch(rb_type(key)) { switch (rb_type(key)) {
case T_STRING: case T_STRING:
if (RB_LIKELY(RBASIC_CLASS(key) == rb_cString)) { if (RB_LIKELY(RBASIC_CLASS(key) == rb_cString)) {
key_to_s = key; key_to_s = key;
@ -1167,7 +1170,7 @@ static void generate_json_array(FBuffer *buffer, struct generate_json_data *data
fbuffer_append_char(buffer, '['); fbuffer_append_char(buffer, '[');
if (RB_UNLIKELY(data->state->array_nl)) fbuffer_append_str(buffer, data->state->array_nl); if (RB_UNLIKELY(data->state->array_nl)) fbuffer_append_str(buffer, data->state->array_nl);
for(i = 0; i < RARRAY_LEN(obj); i++) { for (i = 0; i < RARRAY_LEN(obj); i++) {
if (i > 0) { if (i > 0) {
fbuffer_append_char(buffer, ','); fbuffer_append_char(buffer, ',');
if (RB_UNLIKELY(data->state->array_nl)) fbuffer_append_str(buffer, data->state->array_nl); if (RB_UNLIKELY(data->state->array_nl)) fbuffer_append_str(buffer, data->state->array_nl);
@ -1252,7 +1255,7 @@ static void generate_json_string(FBuffer *buffer, struct generate_json_data *dat
search.chunk_base = NULL; search.chunk_base = NULL;
#endif /* HAVE_SIMD */ #endif /* HAVE_SIMD */
switch(rb_enc_str_coderange(obj)) { switch (rb_enc_str_coderange(obj)) {
case ENC_CODERANGE_7BIT: case ENC_CODERANGE_7BIT:
case ENC_CODERANGE_VALID: case ENC_CODERANGE_VALID:
if (RB_UNLIKELY(data->state->ascii_only)) { if (RB_UNLIKELY(data->state->ascii_only)) {
@ -2116,7 +2119,7 @@ void Init_generator(void)
rb_require("json/ext/generator/state"); rb_require("json/ext/generator/state");
switch(find_simd_implementation()) { switch (find_simd_implementation()) {
#ifdef HAVE_SIMD #ifdef HAVE_SIMD
#ifdef HAVE_SIMD_NEON #ifdef HAVE_SIMD_NEON
case SIMD_NEON: case SIMD_NEON:

View file

@ -540,7 +540,7 @@ static void
json_eat_comments(JSON_ParserState *state) json_eat_comments(JSON_ParserState *state)
{ {
if (state->cursor + 1 < state->end) { if (state->cursor + 1 < state->end) {
switch(state->cursor[1]) { switch (state->cursor[1]) {
case '/': { case '/': {
state->cursor = memchr(state->cursor, '\n', state->end - state->cursor); state->cursor = memchr(state->cursor, '\n', state->end - state->cursor);
if (!state->cursor) { if (!state->cursor) {

View file

@ -18,7 +18,8 @@ typedef enum {
#define HAVE_BUILTIN_CTZLL 0 #define HAVE_BUILTIN_CTZLL 0
#endif #endif
static inline uint32_t trailing_zeros64(uint64_t input) { static inline uint32_t trailing_zeros64(uint64_t input)
{
#if HAVE_BUILTIN_CTZLL #if HAVE_BUILTIN_CTZLL
return __builtin_ctzll(input); return __builtin_ctzll(input);
#else #else
@ -32,7 +33,8 @@ static inline uint32_t trailing_zeros64(uint64_t input) {
#endif #endif
} }
static inline int trailing_zeros(int input) { static inline int trailing_zeros(int input)
{
#if HAVE_BUILTIN_CTZLL #if HAVE_BUILTIN_CTZLL
return __builtin_ctz(input); return __builtin_ctz(input);
#else #else
@ -59,7 +61,8 @@ static inline int trailing_zeros(int input) {
#include <arm_neon.h> #include <arm_neon.h>
#define FIND_SIMD_IMPLEMENTATION_DEFINED 1 #define FIND_SIMD_IMPLEMENTATION_DEFINED 1
static inline SIMD_Implementation find_simd_implementation(void) { static inline SIMD_Implementation find_simd_implementation(void)
{
return SIMD_NEON; return SIMD_NEON;
} }
@ -89,7 +92,7 @@ static inline FORCE_INLINE uint64_t compute_chunk_mask_neon(const char *ptr)
static inline FORCE_INLINE int string_scan_simd_neon(const char **ptr, const char *end, uint64_t *mask) static inline FORCE_INLINE int string_scan_simd_neon(const char **ptr, const char *end, uint64_t *mask)
{ {
while(*ptr + sizeof(uint8x16_t) <= end) { while (*ptr + sizeof(uint8x16_t) <= end) {
uint64_t chunk_mask = compute_chunk_mask_neon(*ptr); uint64_t chunk_mask = compute_chunk_mask_neon(*ptr);
if (chunk_mask) { if (chunk_mask) {
*mask = chunk_mask; *mask = chunk_mask;
@ -161,7 +164,8 @@ static inline TARGET_SSE2 FORCE_INLINE int string_scan_simd_sse2(const char **pt
#include <cpuid.h> #include <cpuid.h>
#endif /* HAVE_CPUID_H */ #endif /* HAVE_CPUID_H */
static inline SIMD_Implementation find_simd_implementation(void) { static inline SIMD_Implementation find_simd_implementation(void)
{
// TODO Revisit. I think the SSE version now only uses SSE2 instructions. // TODO Revisit. I think the SSE version now only uses SSE2 instructions.
if (__builtin_cpu_supports("sse2")) { if (__builtin_cpu_supports("sse2")) {
return SIMD_SSE2; return SIMD_SSE2;
@ -176,7 +180,8 @@ static inline SIMD_Implementation find_simd_implementation(void) {
#endif /* JSON_ENABLE_SIMD */ #endif /* JSON_ENABLE_SIMD */
#ifndef FIND_SIMD_IMPLEMENTATION_DEFINED #ifndef FIND_SIMD_IMPLEMENTATION_DEFINED
static inline SIMD_Implementation find_simd_implementation(void) { static inline SIMD_Implementation find_simd_implementation(void)
{
return SIMD_NONE; return SIMD_NONE;
} }
#endif #endif