aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-03-12 15:59:32 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-03-12 15:59:32 -0300
commitf292760f12022a83cf01e788482a264aeeb3c276 (patch)
tree4d5b490657f6ea18f2c754eed2991e2fd0c570cf
parent1124cb12474b4398384bdefbf12a0769521e17bb (diff)
downloadlua-f292760f12022a83cf01e788482a264aeeb3c276.tar.gz
lua-f292760f12022a83cf01e788482a264aeeb3c276.tar.bz2
lua-f292760f12022a83cf01e788482a264aeeb3c276.zip
small optimization in luaL_addlstring (avoid adding chars one by one)
(suggested by Chuck Coffing)
-rw-r--r--lauxlib.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/lauxlib.c b/lauxlib.c
index 8e49c311..46c7e4f9 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.200 2010/02/18 19:32:41 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.201 2010/02/18 19:37:57 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -393,8 +393,19 @@ LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) {
393 393
394 394
395LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { 395LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {
396 while (l--) 396 while (l) {
397 luaL_addchar(B, *s++); 397 size_t space = bufffree(B);
398 if (space == 0) {
399 luaL_prepbuffer(B);
400 lua_assert(bufffree(B) == LUAL_BUFFERSIZE);
401 space = LUAL_BUFFERSIZE;
402 }
403 if (space > l) space = l;
404 memcpy(B->p, s, space);
405 B->p += space;
406 s += space;
407 l -= space;
408 }
398} 409}
399 410
400 411