summaryrefslogtreecommitdiffhomepage
path: root/src/string.c
diff options
context:
space:
mode:
authordearblue <[email protected]>2019-07-14 18:55:38 +0900
committerdearblue <[email protected]>2019-07-14 18:55:38 +0900
commit7b260d9c2de4436d6e8b09ba4fd524782934153f (patch)
tree99581f5f3b98279075f29a15597322ac6f144221 /src/string.c
parenta7be9f1cab2e9b09995bb388e1219784920610e7 (diff)
downloadmruby-7b260d9c2de4436d6e8b09ba4fd524782934153f.tar.gz
mruby-7b260d9c2de4436d6e8b09ba4fd524782934153f.zip
Improve `utf8len()` performance with UTF-8
Diffstat (limited to 'src/string.c')
-rw-r--r--src/string.c2
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)