[#19457] equality between "a" and Exception.new("a") — Tanaka Akira <akr@...17n.org>

ふと気がついたのですが、

39 messages 2003/02/02
[#19460] Re: equality between "a" and Exception.new("a") — matz@... (Yukihiro Matsumoto) 2003/02/03

まつもと ゆきひろです

[#19473] Re: equality between "a" and Exception.new("a") — Tanaka Akira <akr@...17n.org> 2003/02/04

In article <1044245817.592933.31973.nullmailer@picachu.netlab.jp>,

[#19474] Re: equality between "a" and Exception.new("a") — matz@... (Yukihiro Matsumoto) 2003/02/04

まつもと ゆきひろです

[#19475] Re: equality between "a" and Exception.new("a") — Tanaka Akira <akr@...17n.org> 2003/02/04

In article <1044329220.257740.28127.nullmailer@picachu.netlab.jp>,

[#19476] Re: equality between "a" and Exception.new("a") — matz@... (Yukihiro Matsumoto) 2003/02/04

まつもと ゆきひろです

[#19477] Re: equality between "a" and Exception.new("a") — Tanaka Akira <akr@...17n.org> 2003/02/04

In article <1044331431.138035.28173.nullmailer@picachu.netlab.jp>,

[#19478] Re: equality between "a" and Exception.new("a") — matz@... (Yukihiro Matsumoto) 2003/02/04

まつもと ゆきひろです

[#19479] Re: equality between "a" and Exception.new("a") — Tanaka Akira <akr@...17n.org> 2003/02/04

In article <1044332948.099873.28206.nullmailer@picachu.netlab.jp>,

[#19482] Re: equality between "a" and Exception.new("a") — matz@... (Yukihiro Matsumoto) 2003/02/04

まつもと ゆきひろです

[#19486] Re: equality between "a" and Exception.new("a") — Tanaka Akira <akr@...17n.org> 2003/02/04

In article <1044338964.502066.28474.nullmailer@picachu.netlab.jp>,

[#19491] Re: equality between "a" and Exception.new("a") — matz@... (Yukihiro Matsumoto) 2003/02/04

まつもと ゆきひろです

[#19493] Re: equality between "a" and Exception.new("a") — matz@... (Yukihiro Matsumoto) 2003/02/04

まつもと ゆきひろです

[#19556] compare between String and Exception — Tanaka Akira <akr@...17n.org> 2003/02/12

さらに気が付いたのですが、

[#19514] [Oniguruma] Version 1.7.1 — "K.Kosako" <kosako@...>

ftp.ruby-lang.orgに、onigd20030207.tar.gzを置きました。

19 messages 2003/02/07

[#19548] [PATCH] file.c for (PR#389) and (PR#390) — nobu.nakada@...

なかだです。

20 messages 2003/02/11
[#19572] Re: [PATCH] file.c for (PR#389) and (PR#390) — pegacorn@... 2003/02/14

From: nobu.nakada@nifty.ne.jp

[#19648] Re: SEGV at search_method in eval.c (PR#400) — nobu.nakada@...

なかだです。

13 messages 2003/02/24

[ruby-dev:19464] Re: Karp-Rabin (Re: new keyword once)

From: nobu.nakada@...
Date: 2003-02-03 07:07:02 UTC
List: ruby-dev #19464
なかだです。

At Mon, 3 Feb 2003 13:11:55 +0900,
Yukihiro Matsumoto wrote:
> |乗算よりもシフトのほうが速そうな気がするんですが、どうなんでしょ
> |うか。あまり変わらないかも。
> 
> 手元でテストしたらなんかマッチしないケースがあるみたい。

たしかに。

しかしせいぜい2,3%くらい。


Index: re.c
===================================================================
RCS file: /cvs/ruby/src/ruby/re.c,v
retrieving revision 1.93
diff -u -2 -p -r1.93 re.c
--- re.c	3 Feb 2003 05:34:15 -0000	1.93
+++ re.c	3 Feb 2003 07:04:56 -0000
@@ -104,8 +104,9 @@ 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)<<d) + (b))
 
     s = y; e = s + n - m + 1;
@@ -114,12 +115,12 @@ rb_memsearch(x0, m, y0, n)
     /* computes d = 2^(m-1) with
        the left-shift operator */
-    for (d = i = 1; i < m; ++i)
-	d = (d<<1);
+    d = sizeof(hx) * CHAR_BIT - 1;
+    if (d > 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 */
@@ -128,5 +129,5 @@ rb_memsearch(x0, m, y0, n)
 		return s-y;
 	    }
-	    hy = KR_REHASH(casetable[*s], casetable[*(s+m)], hy);
+	    hy = KR_REHASH(casetable[*s], casetable[*(s+d)], hy);
 	    s++;
 	}
@@ -134,7 +135,7 @@ rb_memsearch(x0, m, y0, n)
     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 */
@@ -143,5 +144,5 @@ rb_memsearch(x0, m, y0, n)
 		return s-y;
 	    }
-	    hy = KR_REHASH(*s, *(s+m), hy);
+	    hy = KR_REHASH(*s, *(s+d), hy);
 	    s++;
 	}


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

In This Thread