aboutsummaryrefslogtreecommitdiff
path: root/lauxlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-09-06 10:58:55 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-09-06 10:58:55 -0300
commit69b77b6fde32cdf5dcaeeb92996bf6c4697e0b4f (patch)
treee55a5cee9fb21522015f710712577c23243e2be2 /lauxlib.c
parent997f11f54322883c3181225f29d101a597f31730 (diff)
downloadlua-69b77b6fde32cdf5dcaeeb92996bf6c4697e0b4f.tar.gz
lua-69b77b6fde32cdf5dcaeeb92996bf6c4697e0b4f.tar.bz2
lua-69b77b6fde32cdf5dcaeeb92996bf6c4697e0b4f.zip
Changed the growth rate of string buffers
The growth rate of string buffers was reduced from 2 to 1.5 (3/2). As string buffers start larger (256~1024 bytes), they don't need to grow that fast. Moreover, a lower rate allows multiplicative growth up to larger sizes (3/2 of the maximum). (After that, the growth becomes linear, which is mostly useless.)
Diffstat (limited to 'lauxlib.c')
-rw-r--r--lauxlib.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/lauxlib.c b/lauxlib.c
index cba5df9b..4ca6c654 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -526,14 +526,14 @@ static void newbox (lua_State *L) {
526 526
527/* 527/*
528** Compute new size for buffer 'B', enough to accommodate extra 'sz' 528** Compute new size for buffer 'B', enough to accommodate extra 'sz'
529** bytes. (The test for "double is not big enough" also gets the 529** bytes. (The test for "not big enough" also gets the case when the
530** case when the multiplication by 2 overflows.) 530** computation of 'newsize' overflows.)
531*/ 531*/
532static size_t newbuffsize (luaL_Buffer *B, size_t sz) { 532static size_t newbuffsize (luaL_Buffer *B, size_t sz) {
533 size_t newsize = B->size * 2; /* double buffer size */ 533 size_t newsize = (B->size / 2) * 3; /* buffer size * 1.5 */
534 if (l_unlikely(MAX_SIZET - sz < B->n)) /* overflow in (B->n + sz)? */ 534 if (l_unlikely(MAX_SIZET - sz < B->n)) /* overflow in (B->n + sz)? */
535 return luaL_error(B->L, "buffer too large"); 535 return luaL_error(B->L, "buffer too large");
536 if (newsize < B->n + sz) /* double is not big enough? */ 536 if (newsize < B->n + sz) /* not big enough? */
537 newsize = B->n + sz; 537 newsize = B->n + sz;
538 return newsize; 538 return newsize;
539} 539}