diff options
author | Mike Pall <mike> | 2012-08-26 19:41:35 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2012-08-26 19:41:35 +0200 |
commit | c0efa6f00ed757bc05d3a0874f98c91fcb88dc68 (patch) | |
tree | ead5e444f8385b5f6e3ee8c0822268a287437f73 /src/lib_string.c | |
parent | cf3a2630443e3522d68c62a184df11ad1914ec44 (diff) | |
download | luajit-c0efa6f00ed757bc05d3a0874f98c91fcb88dc68.tar.gz luajit-c0efa6f00ed757bc05d3a0874f98c91fcb88dc68.tar.bz2 luajit-c0efa6f00ed757bc05d3a0874f98c91fcb88dc68.zip |
Replace divisions with simpler code.
Diffstat (limited to 'src/lib_string.c')
-rw-r--r-- | src/lib_string.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/lib_string.c b/src/lib_string.c index 89ec4f25..d4a2b0d1 100644 --- a/src/lib_string.c +++ b/src/lib_string.c | |||
@@ -668,19 +668,22 @@ static void addquoted(lua_State *L, luaL_Buffer *b, int arg) | |||
668 | const char *s = strdata(str); | 668 | const char *s = strdata(str); |
669 | luaL_addchar(b, '"'); | 669 | luaL_addchar(b, '"'); |
670 | while (len--) { | 670 | while (len--) { |
671 | if (*s == '"' || *s == '\\' || *s == '\n') { | 671 | uint32_t c = uchar(*s); |
672 | if (c == '"' || c == '\\' || c == '\n') { | ||
672 | luaL_addchar(b, '\\'); | 673 | luaL_addchar(b, '\\'); |
673 | luaL_addchar(b, *s); | 674 | } else if (lj_char_iscntrl(c)) { /* This can only be 0-31 or 127. */ |
674 | } else if (lj_char_iscntrl(uchar(*s))) { | 675 | uint32_t d; |
675 | uint32_t c1, c2, c3; | ||
676 | luaL_addchar(b, '\\'); | 676 | luaL_addchar(b, '\\'); |
677 | c1 = uchar(*s); c3 = c1 % 10; c1 /= 10; c2 = c1 % 10; c1 /= 10; | 677 | if (c >= 100 || lj_char_isdigit(uchar(s[1]))) { |
678 | if (c1 + lj_char_isdigit(uchar(s[1]))) luaL_addchar(b, '0' + c1); | 678 | luaL_addchar(b, '0'+(c >= 100)); if (c >= 100) c -= 100; |
679 | if (c2 + (c1 + lj_char_isdigit(uchar(s[1])))) luaL_addchar(b, '0' + c2); | 679 | goto tens; |
680 | luaL_addchar(b, '0' + c3); | 680 | } else if (c >= 10) { |
681 | } else { | 681 | tens: |
682 | luaL_addchar(b, *s); | 682 | d = (c * 205) >> 11; c -= d * 10; luaL_addchar(b, '0'+d); |
683 | } | ||
684 | c += '0'; | ||
683 | } | 685 | } |
686 | luaL_addchar(b, c); | ||
684 | s++; | 687 | s++; |
685 | } | 688 | } |
686 | luaL_addchar(b, '"'); | 689 | luaL_addchar(b, '"'); |