mirror of
https://github.com/lua/lua.git
synced 2025-01-28 06:03:00 +08:00
small optimization in luaL_addlstring (avoid adding chars one by one)
(suggested by Chuck Coffing)
This commit is contained in:
parent
1124cb1247
commit
f292760f12
17
lauxlib.c
17
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
|
** Auxiliary functions for building Lua libraries
|
||||||
** See Copyright Notice in lua.h
|
** 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) {
|
LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {
|
||||||
while (l--)
|
while (l) {
|
||||||
luaL_addchar(B, *s++);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user