diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2015-12-31 21:20:51 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2015-12-31 21:20:51 +0900 |
| commit | 31b8469bffc4c30429a5abf865edde251bed7241 (patch) | |
| tree | ee9334c258b7113d613fad61782f11b60986eebf /src | |
| parent | 1d7d7062fcfbe2ea389a20732287d3247985e289 (diff) | |
| parent | 6c1b6ef7a5d849ccfcb8cbd163443f983f264857 (diff) | |
| download | mruby-31b8469bffc4c30429a5abf865edde251bed7241.tar.gz mruby-31b8469bffc4c30429a5abf865edde251bed7241.zip | |
Merge pull request #3067 from ksss/use-memchr
Use memchr for performance
Diffstat (limited to 'src')
| -rw-r--r-- | src/string.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/string.c b/src/string.c index 6664eabd6..0d31a304f 100644 --- a/src/string.c +++ b/src/string.c @@ -352,12 +352,12 @@ mrb_memsearch(const void *x0, mrb_int m, const void *y0, mrb_int n) return 0; } else if (m == 1) { - const unsigned char *ys = y, *ye = ys + n; - for (; y < ye; ++y) { - if (*x == *y) - return y - ys; - } - return -1; + const unsigned char *ys = memchr(y, *x, n); + + if (ys) + return ys - y; + else + return -1; } return mrb_memsearch_qs((const unsigned char *)x0, m, (const unsigned char *)y0, n); } |
