Blua: small optimization in luaL_addlstring (avoid adding chars one by one)

https://github.com/lua/lua/commit/f292760f12022a83cf01e788482a264aeeb3c276
This commit is contained in:
Alug authored and Alug committed 2026-03-13 18:55:55 +01:00
1 parent edc10a35a1
commit 90b5f9050a
1 file changed
+14 -2
+14 -2
View File
@@ -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;
}
}