diff options
| author | Mike Pall <mike> | 2026-08-01 11:37:20 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2026-08-01 11:37:20 +0200 |
| commit | 594472579a9ea43fd2fc65be125570900b8bba12 (patch) | |
| tree | e86cd67e865fa928a90181e84d0625ee4a5fee42 /src | |
| parent | afa81a57382ce7e747b493220e79573f23205ab0 (diff) | |
| download | luajit-594472579a9ea43fd2fc65be125570900b8bba12.tar.gz luajit-594472579a9ea43fd2fc65be125570900b8bba12.tar.bz2 luajit-594472579a9ea43fd2fc65be125570900b8bba12.zip | |
Optimize common 1-char case of string.sub/string.byte.
Reported by Kacper Michajłow. #1497
Diffstat (limited to 'src')
| -rw-r--r-- | src/lj_ffrecord.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index 4349f748f..ef8e554bd 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c | |||
| @@ -846,6 +846,17 @@ static void LJ_FASTCALL recff_string_range(jit_State *J, RecordFFData *rd) | |||
| 846 | lj_ir_kint(J, 1)); | 846 | lj_ir_kint(J, 1)); |
| 847 | end = end+(int32_t)str->len+1; | 847 | end = end+(int32_t)str->len+1; |
| 848 | } else if ((MSize)end <= str->len) { | 848 | } else if ((MSize)end <= str->len) { |
| 849 | if (trstart == trend && start != 0) { /* Common 1-char case. */ | ||
| 850 | TRef trptr, tr = emitir(IRTI(IR_ADD), trstart, lj_ir_kint(J, -1)); | ||
| 851 | emitir(IRTGI(IR_ULT), tr, trlen); | ||
| 852 | trptr = emitir(IRT(IR_STRREF, IRT_PGC), trstr, tr); | ||
| 853 | if (rd->data) { /* Return string.sub result. */ | ||
| 854 | J->base[0] = emitir(IRT(IR_SNEW, IRT_STR), trptr, lj_ir_kint(J, 1)); | ||
| 855 | } else { /* Return string.byte result. */ | ||
| 856 | J->base[0] = emitir(IRT(IR_XLOAD, IRT_U8), trptr, IRXLOAD_READONLY); | ||
| 857 | } | ||
| 858 | return; | ||
| 859 | } | ||
| 849 | emitir(IRTGI(IR_ULE), trend, trlen); | 860 | emitir(IRTGI(IR_ULE), trend, trlen); |
| 850 | } else { | 861 | } else { |
| 851 | emitir(IRTGI(IR_GT), trend, trlen); | 862 | emitir(IRTGI(IR_GT), trend, trlen); |
