mirror of
https://github.com/bellard/quickjs.git
synced 2025-11-15 10:12:14 +03:00
optimized string_buffer_putc()
This commit is contained in:
28
quickjs.c
28
quickjs.c
@@ -3610,7 +3610,7 @@ static no_inline int string_buffer_realloc(StringBuffer *s, int new_len, int c)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static no_inline int string_buffer_putc_slow(StringBuffer *s, uint32_t c)
|
static no_inline int string_buffer_putc16_slow(StringBuffer *s, uint32_t c)
|
||||||
{
|
{
|
||||||
if (unlikely(s->len >= s->size)) {
|
if (unlikely(s->len >= s->size)) {
|
||||||
if (string_buffer_realloc(s, s->len + 1, c))
|
if (string_buffer_realloc(s, s->len + 1, c))
|
||||||
@@ -3655,11 +3655,10 @@ static int string_buffer_putc16(StringBuffer *s, uint32_t c)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return string_buffer_putc_slow(s, c);
|
return string_buffer_putc16_slow(s, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 0 <= c <= 0x10ffff */
|
static int string_buffer_putc_slow(StringBuffer *s, uint32_t c)
|
||||||
static int string_buffer_putc(StringBuffer *s, uint32_t c)
|
|
||||||
{
|
{
|
||||||
if (unlikely(c >= 0x10000)) {
|
if (unlikely(c >= 0x10000)) {
|
||||||
/* surrogate pair */
|
/* surrogate pair */
|
||||||
@@ -3670,6 +3669,27 @@ static int string_buffer_putc(StringBuffer *s, uint32_t c)
|
|||||||
return string_buffer_putc16(s, c);
|
return string_buffer_putc16(s, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 0 <= c <= 0x10ffff */
|
||||||
|
static inline int string_buffer_putc(StringBuffer *s, uint32_t c)
|
||||||
|
{
|
||||||
|
if (likely(s->len < s->size)) {
|
||||||
|
if (s->is_wide_char) {
|
||||||
|
if (c < 0x10000) {
|
||||||
|
s->str->u.str16[s->len++] = c;
|
||||||
|
return 0;
|
||||||
|
} else if (likely((s->len + 1) < s->size)) {
|
||||||
|
s->str->u.str16[s->len++] = get_hi_surrogate(c);
|
||||||
|
s->str->u.str16[s->len++] = get_lo_surrogate(c);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else if (c < 0x100) {
|
||||||
|
s->str->u.str8[s->len++] = c;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return string_buffer_putc_slow(s, c);
|
||||||
|
}
|
||||||
|
|
||||||
static int string_getc(const JSString *p, int *pidx)
|
static int string_getc(const JSString *p, int *pidx)
|
||||||
{
|
{
|
||||||
int idx, c, c1;
|
int idx, c, c1;
|
||||||
|
|||||||
Reference in New Issue
Block a user