Optimize common 1-char case of string.sub/string.byte.
Reported by Kacper Michajłow. #1497
This commit is contained in:
parent
afa81a5738
commit
594472579a
@ -846,6 +846,17 @@ static void LJ_FASTCALL recff_string_range(jit_State *J, RecordFFData *rd)
|
|||||||
lj_ir_kint(J, 1));
|
lj_ir_kint(J, 1));
|
||||||
end = end+(int32_t)str->len+1;
|
end = end+(int32_t)str->len+1;
|
||||||
} else if ((MSize)end <= str->len) {
|
} else if ((MSize)end <= str->len) {
|
||||||
|
if (trstart == trend && start != 0) { /* Common 1-char case. */
|
||||||
|
TRef trptr, tr = emitir(IRTI(IR_ADD), trstart, lj_ir_kint(J, -1));
|
||||||
|
emitir(IRTGI(IR_ULT), tr, trlen);
|
||||||
|
trptr = emitir(IRT(IR_STRREF, IRT_PGC), trstr, tr);
|
||||||
|
if (rd->data) { /* Return string.sub result. */
|
||||||
|
J->base[0] = emitir(IRT(IR_SNEW, IRT_STR), trptr, lj_ir_kint(J, 1));
|
||||||
|
} else { /* Return string.byte result. */
|
||||||
|
J->base[0] = emitir(IRT(IR_XLOAD, IRT_U8), trptr, IRXLOAD_READONLY);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
emitir(IRTGI(IR_ULE), trend, trlen);
|
emitir(IRTGI(IR_ULE), trend, trlen);
|
||||||
} else {
|
} else {
|
||||||
emitir(IRTGI(IR_GT), trend, trlen);
|
emitir(IRTGI(IR_GT), trend, trlen);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user