String buffers, part 3d: Compile string buffer methods and functions.

Sponsored by fmad.io.
This commit is contained in:
Mike Pall
2021-07-19 16:53:30 +02:00
parent 2182630903
commit 29bc1f04ac
18 changed files with 625 additions and 87 deletions

View File

@@ -108,6 +108,25 @@ char * LJ_FASTCALL lj_buf_tmp(lua_State *L, MSize sz)
return lj_buf_need(sb, sz);
}
#if LJ_HASBUFFER && LJ_HASJIT
void lj_bufx_set(SBufExt *sbx, const char *p, MSize len, GCobj *ref)
{
lua_State *L = sbufL(sbx);
lj_bufx_free(L, sbx);
lj_bufx_set_cow(L, sbx, p, len);
setgcref(sbx->cowref, ref);
lj_gc_objbarrier(L, (GCudata *)sbx - 1, ref);
}
#if LJ_HASFFI
MSize LJ_FASTCALL lj_bufx_more(SBufExt *sbx, MSize sz)
{
lj_buf_more((SBuf *)sbx, sz);
return sbufleft(sbx);
}
#endif
#endif
/* -- Low-level buffer put operations ------------------------------------- */
SBuf *lj_buf_putmem(SBuf *sb, const void *q, MSize len)
@@ -118,14 +137,27 @@ SBuf *lj_buf_putmem(SBuf *sb, const void *q, MSize len)
return sb;
}
SBuf * LJ_FASTCALL lj_buf_putchar(SBuf *sb, int c)
#if LJ_HASJIT || LJ_HASFFI
static LJ_NOINLINE SBuf * LJ_FASTCALL lj_buf_putchar2(SBuf *sb, int c)
{
char *w = lj_buf_more(sb, 1);
char *w = lj_buf_more2(sb, 1);
*w++ = (char)c;
sb->w = w;
return sb;
}
SBuf * LJ_FASTCALL lj_buf_putchar(SBuf *sb, int c)
{
char *w = sb->w;
if (LJ_LIKELY(w < sb->e)) {
*w++ = (char)c;
sb->w = w;
return sb;
}
return lj_buf_putchar2(sb, c);
}
#endif
SBuf * LJ_FASTCALL lj_buf_putstr(SBuf *sb, GCstr *s)
{
MSize len = s->len;