[ruby/json] generator.c: Optimize by combining calls to fbuffer_append
https://github.com/ruby/json/commit/62301c0bc3
This commit is contained in:
parent
74d459fd52
commit
934d67b415
@ -43,7 +43,7 @@ static void convert_UTF8_to_JSON(FBuffer *out_buffer, VALUE in_string, bool out_
|
|||||||
unsigned long in_utf8_len = RSTRING_LEN(in_string);
|
unsigned long in_utf8_len = RSTRING_LEN(in_string);
|
||||||
bool in_is_ascii_only = rb_enc_str_asciionly_p(in_string);
|
bool in_is_ascii_only = rb_enc_str_asciionly_p(in_string);
|
||||||
|
|
||||||
unsigned long pos;
|
unsigned long beg = 0, pos;
|
||||||
|
|
||||||
for (pos = 0; pos < in_utf8_len;) {
|
for (pos = 0; pos < in_utf8_len;) {
|
||||||
uint32_t ch;
|
uint32_t ch;
|
||||||
@ -89,6 +89,9 @@ static void convert_UTF8_to_JSON(FBuffer *out_buffer, VALUE in_string, bool out_
|
|||||||
|
|
||||||
/* JSON encoding */
|
/* JSON encoding */
|
||||||
if (should_escape) {
|
if (should_escape) {
|
||||||
|
if (pos > beg)
|
||||||
|
fbuffer_append(out_buffer, &in_utf8_str[beg], pos - beg);
|
||||||
|
beg = pos + ch_len;
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case '"': fbuffer_append(out_buffer, "\\\"", 2); break;
|
case '"': fbuffer_append(out_buffer, "\\\"", 2); break;
|
||||||
case '\\': fbuffer_append(out_buffer, "\\\\", 2); break;
|
case '\\': fbuffer_append(out_buffer, "\\\\", 2); break;
|
||||||
@ -124,12 +127,12 @@ static void convert_UTF8_to_JSON(FBuffer *out_buffer, VALUE in_string, bool out_
|
|||||||
fbuffer_append(out_buffer, scratch, 12);
|
fbuffer_append(out_buffer, scratch, 12);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
fbuffer_append(out_buffer, &in_utf8_str[pos], ch_len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pos += ch_len;
|
pos += ch_len;
|
||||||
}
|
}
|
||||||
|
if (beg < in_utf8_len)
|
||||||
|
fbuffer_append(out_buffer, &in_utf8_str[beg], in_utf8_len - beg);
|
||||||
RB_GC_GUARD(in_string);
|
RB_GC_GUARD(in_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user