diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-02-04 23:33:16 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-02-04 23:33:16 +0900 |
| commit | 25e4ec3f377275c7be49c9fab0b1cac46621085d (patch) | |
| tree | 65035fbe99d01a62f3e2e99c103019c12af21215 /src/string.c | |
| parent | 5e514c910fdde7ec29c9110e8c9535d8e83b2a8f (diff) | |
| download | mruby-25e4ec3f377275c7be49c9fab0b1cac46621085d.tar.gz mruby-25e4ec3f377275c7be49c9fab0b1cac46621085d.zip | |
cache UTF8 status for utf8_strlen(); ref #980
Diffstat (limited to 'src/string.c')
| -rw-r--r-- | src/string.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/string.c b/src/string.c index 2b01cc3a5..8d79defe0 100644 --- a/src/string.c +++ b/src/string.c @@ -273,11 +273,17 @@ utf8_strlen(mrb_value str, mrb_int len) mrb_int total = 0; char* p = RSTRING_PTR(str); char* e = p; + if (RSTRING(str)->flags & MRB_STR_NO_UTF) { + return RSTRING_LEN(str); + } e += len < 0 ? RSTRING_LEN(str) : len; while (p<e) { p += utf8len(p, e); total++; } + if (RSTRING_LEN(str) == total) { + RSTRING(str)->flags |= MRB_STR_NO_UTF; + } return total; } @@ -652,6 +658,7 @@ MRB_API void mrb_str_modify(mrb_state *mrb, struct RString *s) { check_frozen(mrb, s); + s->flags &= ~MRB_STR_NO_UTF; if (RSTR_SHARED_P(s)) { mrb_shared_string *shared = s->as.heap.aux.shared; |
