aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2012-08-26 19:41:35 +0200
committerMike Pall <mike>2012-08-26 19:41:35 +0200
commitc0efa6f00ed757bc05d3a0874f98c91fcb88dc68 (patch)
treeead5e444f8385b5f6e3ee8c0822268a287437f73
parentcf3a2630443e3522d68c62a184df11ad1914ec44 (diff)
downloadluajit-c0efa6f00ed757bc05d3a0874f98c91fcb88dc68.tar.gz
luajit-c0efa6f00ed757bc05d3a0874f98c91fcb88dc68.tar.bz2
luajit-c0efa6f00ed757bc05d3a0874f98c91fcb88dc68.zip
Replace divisions with simpler code.
-rw-r--r--src/lib_string.c23
-rw-r--r--src/lj_bcwrite.c2
2 files changed, 14 insertions, 11 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, '"');
diff --git a/src/lj_bcwrite.c b/src/lj_bcwrite.c
index 27f08fe8..5050da07 100644
--- a/src/lj_bcwrite.c
+++ b/src/lj_bcwrite.c
@@ -324,7 +324,7 @@ static void bcwrite_proto(BCWriteCtx *ctx, GCproto *pt)
324 /* Pass buffer to writer function. */ 324 /* Pass buffer to writer function. */
325 if (ctx->status == 0) { 325 if (ctx->status == 0) {
326 MSize n = ctx->sb.n - 5; 326 MSize n = ctx->sb.n - 5;
327 MSize nn = 1 + lj_fls(n)/7; 327 MSize nn = (lj_fls(n)+8)*9 >> 6;
328 ctx->sb.n = 5 - nn; 328 ctx->sb.n = 5 - nn;
329 bcwrite_uleb128(ctx, n); /* Fill in final size. */ 329 bcwrite_uleb128(ctx, n); /* Fill in final size. */
330 lua_assert(ctx->sb.n == 5); 330 lua_assert(ctx->sb.n == 5);