From 056585d6dc58c4b9b1e4bf5e58c0bc81b5122fc6 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 3 Feb 2003 07:34:06 +0000 Subject: * re.c (rb_memsearch): a little improvement. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3434 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- re.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 're.c') diff --git a/re.c b/re.c index 8828119728..dbf9bdf69a 100644 --- a/re.c +++ b/re.c @@ -103,46 +103,47 @@ rb_memsearch(x0, m, y0, n) { unsigned char *x = x0, *y = y0; unsigned char *s, *e; - long d, i; + long i; + int d; unsigned long hx, hy; -#define KR_REHASH(a, b, h) ((((h) - (a)*d) << 1) + (b)) +#define KR_REHASH(a, b, h) (((h) << 1) - ((a)< m) d = m; if (ruby_ignorecase) { /* Prepare hash value */ - for (hy = hx = i = 0; i < m; ++i) { - hx = ((hx<<1) + casetable[x[i]]); - hy = ((hy<<1) + casetable[s[i]]); + for (hy = hx = i = 0; i < d; ++i) { + hx = KR_REHASH(0, casetable[x[i]], hx); + hy = KR_REHASH(0, casetable[s[i]], hy); } /* Searching */ while (s < e) { if (hx == hy && rb_memcicmp(x, s, m) == 0) { return s-y; } - hy = KR_REHASH(casetable[*s], casetable[*(s+m)], hy); + hy = KR_REHASH(casetable[*s], casetable[*(s+d)], hy); s++; } } else { /* Prepare hash value */ - for (hy = hx = i = 0; i < m; ++i) { - hx = ((hx<<1) + x[i]); - hy = ((hy<<1) + s[i]); + for (hy = hx = i = 0; i < d; ++i) { + hx = KR_REHASH(0, x[i], hx); + hy = KR_REHASH(0, s[i], hy); } /* Searching */ while (s < e) { if (hx == hy && memcmp(x, s, m) == 0) { return s-y; } - hy = KR_REHASH(*s, *(s+m), hy); + hy = KR_REHASH(*s, *(s+d), hy); s++; } } -- cgit v1.2.3