From 90b5f9050adaa97bf2bc20637dc4f2f5fee62c1c Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 3 Dec 2025 16:41:42 +0100 Subject: [PATCH] Blua: small optimization in luaL_addlstring (avoid adding chars one by one) https://github.com/lua/lua/commit/f292760f12022a83cf01e788482a264aeeb3c276 --- src/blua/lauxlib.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/blua/lauxlib.c b/src/blua/lauxlib.c index 5fb454d5e..51605eaf1 100644 --- a/src/blua/lauxlib.c +++ b/src/blua/lauxlib.c @@ -20,6 +20,7 @@ #define lauxlib_c #define LUA_LIB +#include "ldebug.h" #include "lua.h" #include "lauxlib.h" @@ -468,8 +469,19 @@ LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) { LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { - while (l--) - luaL_addchar(B, *s++); + while (l) { + size_t space = bufffree(B); + if (space == 0) { + luaL_prepbuffer(B); + lua_assert(bufffree(B) == LUAL_BUFFERSIZE); + space = LUAL_BUFFERSIZE; + } + if (space > l) space = l; + memcpy(B->p, s, space); + B->p += space; + s += space; + l -= space; + } }