diff options
| author | ruki <[email protected]> | 2026-01-21 22:37:33 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-01-21 22:37:33 +0800 |
| commit | 6ff8486cd3297ca0e93518c33e32678c97128a3f (patch) | |
| tree | de0701cf086caff86c81159756bc3b9abf821f2a | |
| parent | a5d36f788b15128587e6eb020c77db376215e6f4 (diff) | |
improve lastof
| -rw-r--r-- | core/src/xmake/utf8/utf8.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/core/src/xmake/utf8/utf8.c b/core/src/xmake/utf8/utf8.c index 88b41f800..4deba3224 100644 --- a/core/src/xmake/utf8/utf8.c +++ b/core/src/xmake/utf8/utf8.c @@ -381,8 +381,13 @@ tb_long_t xm_utf8_find_impl(tb_char_t const* s, tb_size_t len, tb_char_t const* tb_long_t xm_utf8_lastof_impl(tb_char_t const* s, tb_size_t len, tb_char_t const* sub, tb_size_t sublen) { tb_assert_and_check_return_val(s && sub, 0); + tb_check_return_val(sublen, 0); - if (sublen == 0) return 0; + // optimize for single character search + if (sublen == 1) { + tb_char_t const* p = tb_strrchr(s, sub[0]); + return p ? (tb_long_t)(p - s + 1) : 0; + } tb_char_t const* p = s; tb_char_t const* last = tb_null; |
