bc: simple speedups
function old new delta bc_parse_pushName 20 56 +36 bc_program_index 47 71 +24 bc_parse_pushIndex 52 58 +6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 66/0) Total: 66 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
f706a18f33
commit
ab9a98602f
@ -3439,17 +3439,38 @@ static void bc_parse_push(char i)
|
|||||||
|
|
||||||
static void bc_parse_pushName(char *name)
|
static void bc_parse_pushName(char *name)
|
||||||
{
|
{
|
||||||
|
#if 1
|
||||||
|
BcVec *code = &G.prs.func->code;
|
||||||
|
size_t pos = code->len;
|
||||||
|
size_t len = strlen(name) + 1;
|
||||||
|
|
||||||
|
bc_vec_expand(code, pos + len);
|
||||||
|
strcpy(code->v + pos, name);
|
||||||
|
code->len = pos + len;
|
||||||
|
#else
|
||||||
|
// Smaller code, but way slow:
|
||||||
do {
|
do {
|
||||||
bc_parse_push(*name);
|
bc_parse_push(*name);
|
||||||
} while (*name++);
|
} while (*name++);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Indexes < 0xfc are encoded verbatim, else first byte is
|
||||||
|
// 0xfc, 0xfd, 0xfe or 0xff, encoding "1..4 bytes",
|
||||||
|
// followed by that many bytes, lsb first.
|
||||||
|
// (The above describes 32-bit case).
|
||||||
|
#define SMALL_INDEX_LIMIT (0x100 - sizeof(size_t))
|
||||||
|
|
||||||
static void bc_parse_pushIndex(size_t idx)
|
static void bc_parse_pushIndex(size_t idx)
|
||||||
{
|
{
|
||||||
size_t mask;
|
size_t mask;
|
||||||
unsigned amt;
|
unsigned amt;
|
||||||
|
|
||||||
dbg_lex("%s:%d pushing index %zd", __func__, __LINE__, idx);
|
dbg_lex("%s:%d pushing index %zd", __func__, __LINE__, idx);
|
||||||
|
if (idx < SMALL_INDEX_LIMIT) {
|
||||||
|
goto push_idx;
|
||||||
|
}
|
||||||
|
|
||||||
mask = ((size_t)0xff) << (sizeof(idx) * 8 - 8);
|
mask = ((size_t)0xff) << (sizeof(idx) * 8 - 8);
|
||||||
amt = sizeof(idx);
|
amt = sizeof(idx);
|
||||||
do {
|
do {
|
||||||
@ -3458,9 +3479,10 @@ static void bc_parse_pushIndex(size_t idx)
|
|||||||
amt--;
|
amt--;
|
||||||
} while (amt != 0);
|
} while (amt != 0);
|
||||||
|
|
||||||
bc_parse_push(amt);
|
bc_parse_push(SMALL_INDEX_LIMIT + amt);
|
||||||
|
|
||||||
while (idx != 0) {
|
while (idx != 0) {
|
||||||
|
push_idx:
|
||||||
bc_parse_push((unsigned char)idx);
|
bc_parse_push((unsigned char)idx);
|
||||||
idx >>= 8;
|
idx >>= 8;
|
||||||
}
|
}
|
||||||
@ -5257,6 +5279,11 @@ static size_t bc_program_index(char *code, size_t *bgn)
|
|||||||
size_t res;
|
size_t res;
|
||||||
|
|
||||||
amt = *bytes++;
|
amt = *bytes++;
|
||||||
|
if (amt < SMALL_INDEX_LIMIT) {
|
||||||
|
*bgn += 1;
|
||||||
|
return amt;
|
||||||
|
}
|
||||||
|
amt -= SMALL_INDEX_LIMIT;
|
||||||
*bgn += amt + 1;
|
*bgn += amt + 1;
|
||||||
|
|
||||||
amt *= 8;
|
amt *= 8;
|
||||||
|
Loading…
Reference in New Issue
Block a user