commit f292760f12022a83cf01e788482a264aeeb3c276
parent 1124cb12474b4398384bdefbf12a0769521e17bb
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Fri, 12 Mar 2010 15:59:08 -0300
small optimization in luaL_addlstring (avoid adding chars one by one)
(suggested by Chuck Coffing)
Diffstat:
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/lauxlib.c b/lauxlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.c,v 1.200 2010/02/18 19:32:41 roberto Exp roberto $
+** $Id: lauxlib.c,v 1.201 2010/02/18 19:37:57 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -393,8 +393,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;
+ }
}