summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2009-11-07 15:30:52 +0100
committerFlorian Frank <flori@ping.de>2009-11-07 15:30:52 +0100
commit4ff03a70824f8e4050ec8990b0648c0ea039b384 (patch)
tree1026a8591062356c0a6ae476a0cb2c66411f16ee /ext
parent67602c351b6c1655f853f0ca69341035e9b2c04b (diff)
downloadjson-4ff03a70824f8e4050ec8990b0648c0ea039b384.tar.gz
optimise code path for ascii mode, too
Diffstat (limited to 'ext')
-rw-r--r--ext/json/ext/generator/generator.c58
1 files changed, 31 insertions, 27 deletions
diff --git a/ext/json/ext/generator/generator.c b/ext/json/ext/generator/generator.c
index fabb0ea..079ca90 100644
--- a/ext/json/ext/generator/generator.c
+++ b/ext/json/ext/generator/generator.c
@@ -158,35 +158,39 @@ static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string)
#endif
} else {
/* normal case */
- switch (ch) {
- case '\n':
- fbuffer_append(buffer, "\\n", 2);
- break;
- case '\r':
- fbuffer_append(buffer, "\\r", 2);
- break;
- case '\\':
- fbuffer_append(buffer, "\\\\", 2);
- break;
- case '"':
- fbuffer_append(buffer, "\\\"", 2);
- break;
- case '\t':
- fbuffer_append(buffer, "\\t", 2);
- break;
- case '\f':
- fbuffer_append(buffer, "\\f", 2);
- break;
- case '\b':
- fbuffer_append(buffer, "\\b", 2);
- break;
- default:
- if (ch >= 0x20 && ch <= 0x7f) {
+ if (ch >= 0x20 && ch <= 0x7f) {
+ switch (ch) {
+ case '\\':
+ fbuffer_append(buffer, "\\\\", 2);
+ break;
+ case '"':
+ fbuffer_append(buffer, "\\\"", 2);
+ break;
+ default:
fbuffer_append_char(buffer, ch);
- } else {
+ break;
+ }
+ } else {
+ switch (ch) {
+ case '\n':
+ fbuffer_append(buffer, "\\n", 2);
+ break;
+ case '\r':
+ fbuffer_append(buffer, "\\r", 2);
+ break;
+ case '\t':
+ fbuffer_append(buffer, "\\t", 2);
+ break;
+ case '\f':
+ fbuffer_append(buffer, "\\f", 2);
+ break;
+ case '\b':
+ fbuffer_append(buffer, "\\b", 2);
+ break;
+ default:
unicode_escape_to_buffer(buffer, buf, (UTF16) ch);
- }
- break;
+ break;
+ }
}
}
} else if (ch > UNI_MAX_UTF16) {