summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-12-12 09:17:32 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-12-12 09:17:32 +0000
commitf744cfd8d7cc51d90ae863589ded64c60030b220 (patch)
tree298827428de9003eb9c891aa77fa4247a0959043
parentd307881fe48b126830dd1f57ef3d494d783a0db4 (diff)
* re.c (rb_reg_hash): define Regexp#hash to make regexps to be
hash keys. * re.c (Init_Regexp): define Regexp#eql? (alias to Regexp#==). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3137 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--re.c21
2 files changed, 28 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 9f1b24f..a9da009 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Dec 12 17:27:19 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * re.c (rb_reg_hash): define Regexp#hash to make regexps to be
+ hash keys.
+
+ * re.c (Init_Regexp): define Regexp#eql? (alias to Regexp#==).
+
Thu Dec 12 16:26:31 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* marshal.c (r_object0): singleton class instance can't be loaded.
diff --git a/re.c b/re.c
index 06f6502..8d48273 100644
--- a/re.c
+++ b/re.c
@@ -1057,6 +1057,25 @@ rb_reg_cur_kcode(re)
}
static VALUE
+rb_reg_hash(re)
+ VALUE re;
+{
+ int hashval, len;
+ char *p;
+
+ rb_reg_check(re);
+ hashval = RREGEXP(re)->ptr->options;
+ len = RREGEXP(re)->len;
+ p = RREGEXP(re)->str;
+ while (len--) {
+ hashval = hashval * 33 + *p++;
+ }
+ hashval = hashval + (hashval>>5);
+
+ return INT2FIX(hashval);
+}
+
+static VALUE
rb_reg_equal(re1, re2)
VALUE re1, re2;
{
@@ -1560,6 +1579,8 @@ Init_Regexp()
rb_define_method(rb_cRegexp, "initialize", rb_reg_initialize_m, -1);
rb_define_method(rb_cRegexp, "copy_object", rb_reg_copy_object, 1);
+ rb_define_method(rb_cRegexp, "hash", rb_reg_hash, 0);
+ rb_define_method(rb_cRegexp, "eql?", rb_reg_equal, 1);
rb_define_method(rb_cRegexp, "==", rb_reg_equal, 1);
rb_define_method(rb_cRegexp, "=~", rb_reg_match, 1);
rb_define_method(rb_cRegexp, "===", rb_reg_match, 1);