aboutsummaryrefslogtreecommitdiff
path: root/src/lj_buf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lj_buf.c')
-rw-r--r--src/lj_buf.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/lj_buf.c b/src/lj_buf.c
index 3526a6e5..55a885a9 100644
--- a/src/lj_buf.c
+++ b/src/lj_buf.c
@@ -144,6 +144,30 @@ SBuf * LJ_FASTCALL lj_buf_putstr_upper(SBuf *sb, GCstr *s)
144 return sb; 144 return sb;
145} 145}
146 146
147SBuf *lj_buf_putstr_rep(SBuf *sb, GCstr *s, int32_t rep)
148{
149 MSize len = s->len;
150 if (rep > 0 && len) {
151 uint64_t tlen = (uint64_t)rep * len;
152 char *p;
153 if (LJ_UNLIKELY(tlen > LJ_MAX_STR))
154 lj_err_mem(sbufL(sb));
155 p = lj_buf_more(sb, (MSize)tlen);
156 if (len == 1) { /* Optimize a common case. */
157 uint32_t c = strdata(s)[0];
158 do { *p++ = c; } while (--rep > 0);
159 } else {
160 const char *e = strdata(s) + len;
161 do {
162 const char *q = strdata(s);
163 do { *p++ = *q++; } while (q < e);
164 } while (--rep > 0);
165 }
166 setsbufP(sb, p);
167 }
168 return sb;
169}
170
147GCstr * LJ_FASTCALL lj_buf_tostr(SBuf *sb) 171GCstr * LJ_FASTCALL lj_buf_tostr(SBuf *sb)
148{ 172{
149 return lj_str_new(sbufL(sb), sbufB(sb), sbuflen(sb)); 173 return lj_str_new(sbufL(sb), sbufB(sb), sbuflen(sb));