aboutsummaryrefslogtreecommitdiff
path: root/src/lib_string.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib_string.c')
-rw-r--r--src/lib_string.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/src/lib_string.c b/src/lib_string.c
index 9e8ab900..5fdfcd91 100644
--- a/src/lib_string.c
+++ b/src/lib_string.c
@@ -64,7 +64,7 @@ LJLIB_ASM(string_byte) LJLIB_REC(string_range 0)
64LJLIB_ASM(string_char) 64LJLIB_ASM(string_char)
65{ 65{
66 int i, nargs = (int)(L->top - L->base); 66 int i, nargs = (int)(L->top - L->base);
67 char *buf = lj_str_needbuf(L, &G(L)->tmpbuf, (size_t)nargs); 67 char *buf = lj_buf_tmp(L, (size_t)nargs);
68 for (i = 1; i <= nargs; i++) { 68 for (i = 1; i <= nargs; i++) {
69 int32_t k = lj_lib_checkint(L, i); 69 int32_t k = lj_lib_checkint(L, i);
70 if (!checku8(k)) 70 if (!checku8(k))
@@ -91,8 +91,6 @@ LJLIB_ASM(string_rep)
91 int32_t len = (int32_t)s->len; 91 int32_t len = (int32_t)s->len;
92 global_State *g = G(L); 92 global_State *g = G(L);
93 int64_t tlen; 93 int64_t tlen;
94 const char *src;
95 char *buf;
96 if (k <= 0) { 94 if (k <= 0) {
97 empty: 95 empty:
98 setstrV(L, L->base-1, &g->strempty); 96 setstrV(L, L->base-1, &g->strempty);
@@ -110,31 +108,34 @@ LJLIB_ASM(string_rep)
110 if (tlen > LJ_MAX_STR) 108 if (tlen > LJ_MAX_STR)
111 lj_err_caller(L, LJ_ERR_STROV); 109 lj_err_caller(L, LJ_ERR_STROV);
112 } 110 }
113 if (tlen == 0) goto empty; 111 if (tlen == 0) {
114 buf = lj_str_needbuf(L, &g->tmpbuf, (MSize)tlen); 112 goto empty;
115 src = strdata(s); 113 } else {
116 if (sep) { 114 char *buf = lj_buf_tmp(L, (MSize)tlen), *p = buf;
117 tlen -= sep->len; /* Ignore trailing separator. */ 115 const char *src = strdata(s);
118 if (k > 1) { /* Paste one string and one separator. */ 116 if (sep) {
119 int32_t i; 117 tlen -= sep->len; /* Ignore trailing separator. */
120 i = 0; while (i < len) *buf++ = src[i++]; 118 if (k > 1) { /* Paste one string and one separator. */
121 src = strdata(sep); len = sep->len; 119 int32_t i;
122 i = 0; while (i < len) *buf++ = src[i++]; 120 i = 0; while (i < len) *p++ = src[i++];
123 src = g->tmpbuf.buf; len += s->len; k--; /* Now copy that k-1 times. */ 121 src = strdata(sep); len = sep->len;
122 i = 0; while (i < len) *p++ = src[i++];
123 src = buf; len += s->len; k--; /* Now copy that k-1 times. */
124 }
124 } 125 }
126 do {
127 int32_t i = 0;
128 do { *p++ = src[i++]; } while (i < len);
129 } while (--k > 0);
130 setstrV(L, L->base-1, lj_str_new(L, buf, (size_t)tlen));
125 } 131 }
126 do {
127 int32_t i = 0;
128 do { *buf++ = src[i++]; } while (i < len);
129 } while (--k > 0);
130 setstrV(L, L->base-1, lj_str_new(L, g->tmpbuf.buf, (size_t)tlen));
131 return FFH_RES(1); 132 return FFH_RES(1);
132} 133}
133 134
134LJLIB_ASM(string_reverse) 135LJLIB_ASM(string_reverse)
135{ 136{
136 GCstr *s = lj_lib_checkstr(L, 1); 137 GCstr *s = lj_lib_checkstr(L, 1);
137 lj_str_needbuf(L, &G(L)->tmpbuf, s->len); 138 lj_buf_tmp(L, s->len);
138 return FFH_RETRY; 139 return FFH_RETRY;
139} 140}
140LJLIB_ASM_(string_lower) 141LJLIB_ASM_(string_lower)