diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2012-04-03 16:06:19 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2012-04-03 16:06:19 -0300 |
commit | 462375ba47de2052687b3d17ff2eef4db4cab739 (patch) | |
tree | 2f45eb11fd4f8ca6bcf039cffb14677a94a9376d /lstrlib.c | |
parent | cfbe2333a443447396c6f610d4cc532c8564bde6 (diff) | |
download | lua-462375ba47de2052687b3d17ff2eef4db4cab739.tar.gz lua-462375ba47de2052687b3d17ff2eef4db4cab739.tar.bz2 lua-462375ba47de2052687b3d17ff2eef4db4cab739.zip |
'if' to avoid empty 'memcpy' (may be expensive)
Diffstat (limited to 'lstrlib.c')
-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); |