diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-07-15 05:34:12 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-07-15 05:34:12 +0900 |
| commit | df293c7be1d1495ffbffdefbf85fac128816e2ec (patch) | |
| tree | 832dc84a3600bbc5d503429a6053bfe434c3232b | |
| parent | 38624074e9ae057f8daaceeafcbcd43e10f203d3 (diff) | |
| parent | 7b260d9c2de4436d6e8b09ba4fd524782934153f (diff) | |
| download | mruby-df293c7be1d1495ffbffdefbf85fac128816e2ec.tar.gz mruby-df293c7be1d1495ffbffdefbf85fac128816e2ec.zip | |
Merge pull request #4578 from dearblue/improve-utf8len
Improve `utf8len()` performance with UTF-8
| -rw-r--r-- | src/string.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/string.c b/src/string.c index a6aa9d906..be623deda 100644 --- a/src/string.c +++ b/src/string.c @@ -233,7 +233,9 @@ utf8len(const char* p, const char* e) mrb_int len; mrb_int i; + if ((unsigned char)*p < 0x80) return 1; len = utf8len_codepage[(unsigned char)*p]; + if (len == 1) return 1; if (len > e - p) return 1; for (i = 1; i < len; ++i) if ((p[i] & 0xc0) != 0x80) |
