diff options
-rw-r--r-- | lstrlib.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.172 2011/10/25 12:01:20 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.173 2011/11/30 18:24:56 roberto Exp roberto $ |
3 | ** Standard library for string operations and pattern-matching | 3 | ** Standard library for string operations and pattern-matching |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -119,7 +119,9 @@ static int str_rep (lua_State *L) { | |||
119 | char *p = luaL_buffinitsize(L, &b, totallen); | 119 | char *p = luaL_buffinitsize(L, &b, totallen); |
120 | while (n-- > 1) { /* first n-1 copies (followed by separator) */ | 120 | while (n-- > 1) { /* first n-1 copies (followed by separator) */ |
121 | memcpy(p, s, l * sizeof(char)); p += l; | 121 | memcpy(p, s, l * sizeof(char)); p += l; |
122 | memcpy(p, sep, lsep * sizeof(char)); p += lsep; | 122 | if (lsep > 0) { /* avoid empty 'memcpy' (may be expensive) */ |
123 | memcpy(p, sep, lsep * sizeof(char)); p += lsep; | ||
124 | } | ||
123 | } | 125 | } |
124 | memcpy(p, s, l * sizeof(char)); /* last copy (not followed by separator) */ | 126 | memcpy(p, s, l * sizeof(char)); /* last copy (not followed by separator) */ |
125 | luaL_pushresultsize(&b, totallen); | 127 | luaL_pushresultsize(&b, totallen); |