Skip to content

Commit 69b77b6

Browse files
committed
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.)
1 parent 997f11f commit 69b77b6

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lauxlib.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,14 +526,14 @@ static void newbox (lua_State *L) {
526526

527527
/*
528528
** Compute new size for buffer 'B', enough to accommodate extra 'sz'
529-
** bytes. (The test for "double is not big enough" also gets the
530-
** case when the multiplication by 2 overflows.)
529+
** bytes. (The test for "not big enough" also gets the case when the
530+
** computation of 'newsize' overflows.)
531531
*/
532532
static 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 */
534534
if (l_unlikely(MAX_SIZET - sz < B->n)) /* overflow in (B->n + sz)? */
535535
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? */
537537
newsize = B->n + sz;
538538
return newsize;
539539
}

luaconf.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,14 +747,15 @@
747747

748748
/*
749749
@@ LUA_IDSIZE gives the maximum size for the description of the source
750-
@@ of a function in debug information.
750+
** of a function in debug information.
751751
** CHANGE it if you want a different size.
752752
*/
753753
#define LUA_IDSIZE 60
754754

755755

756756
/*
757-
@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
757+
@@ LUAL_BUFFERSIZE is the initial buffer size used by the lauxlib
758+
** buffer system.
758759
*/
759760
#define LUAL_BUFFERSIZE ((int)(16 * sizeof(void*) * sizeof(lua_Number)))
760761

0 commit comments

Comments
 (0)