diff options
author | Matthew Dempsky <matthew@mochimedia.com> | 2008-09-25 07:25:02 +0000 |
---|---|---|
committer | Matthew Dempsky <matthew@mochimedia.com> | 2008-09-25 07:25:02 +0000 |
commit | b491b960a4780755f4f0a0b99347a1fdcaf7fc43 (patch) | |
tree | d3c6b090fb479e27fb02e7d0e3a851cb8f0d4a2b /simplejson/_speedups.c | |
parent | 5b15243edbfc79c724d15229fb79e45cc4a433d4 (diff) | |
download | simplejson-b491b960a4780755f4f0a0b99347a1fdcaf7fc43.tar.gz |
branchless unicode escaping
git-svn-id: http://simplejson.googlecode.com/svn/trunk@112 a4795897-2c25-0410-b006-0d3caba88fa1
Diffstat (limited to 'simplejson/_speedups.c')
-rw-r--r-- | simplejson/_speedups.c | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/simplejson/_speedups.c b/simplejson/_speedups.c index 3ee5dd1..2308312 100644 --- a/simplejson/_speedups.c +++ b/simplejson/_speedups.c @@ -74,7 +74,6 @@ _build_rval_index_tuple(PyObject *rval, Py_ssize_t idx); static Py_ssize_t ascii_escape_char(Py_UNICODE c, char *output, Py_ssize_t chars) { - Py_UNICODE x; output[chars++] = '\\'; switch (c) { case '\\': output[chars++] = (char)c; break; @@ -91,27 +90,19 @@ ascii_escape_char(Py_UNICODE c, char *output, Py_ssize_t chars) Py_UNICODE v = c - 0x10000; c = 0xd800 | ((v >> 10) & 0x3ff); output[chars++] = 'u'; - x = (c & 0xf000) >> 12; - output[chars++] = (x < 10) ? '0' + x : 'a' + (x - 10); - x = (c & 0x0f00) >> 8; - output[chars++] = (x < 10) ? '0' + x : 'a' + (x - 10); - x = (c & 0x00f0) >> 4; - output[chars++] = (x < 10) ? '0' + x : 'a' + (x - 10); - x = (c & 0x000f); - output[chars++] = (x < 10) ? '0' + x : 'a' + (x - 10); + output[chars++] = "0123456789abcdef"[(c >> 12) & 0xf]; + output[chars++] = "0123456789abcdef"[(c >> 8) & 0xf]; + output[chars++] = "0123456789abcdef"[(c >> 4) & 0xf]; + output[chars++] = "0123456789abcdef"[(c ) & 0xf]; c = 0xdc00 | (v & 0x3ff); output[chars++] = '\\'; } #endif output[chars++] = 'u'; - x = (c & 0xf000) >> 12; - output[chars++] = (x < 10) ? '0' + x : 'a' + (x - 10); - x = (c & 0x0f00) >> 8; - output[chars++] = (x < 10) ? '0' + x : 'a' + (x - 10); - x = (c & 0x00f0) >> 4; - output[chars++] = (x < 10) ? '0' + x : 'a' + (x - 10); - x = (c & 0x000f); - output[chars++] = (x < 10) ? '0' + x : 'a' + (x - 10); + output[chars++] = "0123456789abcdef"[(c >> 12) & 0xf]; + output[chars++] = "0123456789abcdef"[(c >> 8) & 0xf]; + output[chars++] = "0123456789abcdef"[(c >> 4) & 0xf]; + output[chars++] = "0123456789abcdef"[(c ) & 0xf]; } return chars; } |