summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog16
-rw-r--r--array.c11
-rw-r--r--numeric.c1
-rw-r--r--object.c2
-rw-r--r--re.c65
-rw-r--r--string.c11
6 files changed, 65 insertions, 41 deletions
diff --git a/ChangeLog b/ChangeLog
index 0997bae..19b4ecb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+Mon Feb 3 16:49:19 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * object.c (Init_Object): default Object#=== now calls "=="
+ internally.
+
+ * re.c (rb_reg_initialize_m): should honor option status of
+ original regexp.
+
+ * array.c (rb_ary_equal): ary2 should be T_ARRAY (no to_ary
+ conversion).
+
+ * array.c (rb_ary_eql): ditto.
+
+ * string.c (rb_str_equal): str2 should be T_STRING (no to_str
+ conversion).
+
Mon Feb 3 16:32:52 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* re.c (rb_memsearch): a little improvement.
diff --git a/array.c b/array.c
index 7e039ab..2010e13 100644
--- a/array.c
+++ b/array.c
@@ -1563,10 +1563,7 @@ rb_ary_equal(ary1, ary2)
long i;
if (ary1 == ary2) return Qtrue;
- if (TYPE(ary2) != T_ARRAY) {
- ary2 = rb_check_array_type(ary2);
- if (NIL_P(ary2)) return Qfalse;
- }
+ if (TYPE(ary2) != T_ARRAY) return Qfalse;
if (RARRAY(ary1)->len != RARRAY(ary2)->len) return Qfalse;
for (i=0; i<RARRAY(ary1)->len; i++) {
if (!rb_equal(RARRAY(ary1)->ptr[i], RARRAY(ary2)->ptr[i]))
@@ -1582,10 +1579,7 @@ rb_ary_eql(ary1, ary2)
long i;
if (ary1 == ary2) return Qtrue;
- if (TYPE(ary2) != T_ARRAY) {
- ary2 = rb_check_array_type(ary2);
- if (NIL_P(ary2)) return Qfalse;
- }
+ if (TYPE(ary2) != T_ARRAY) return Qfalse;
if (RARRAY(ary1)->len != RARRAY(ary2)->len) return Qfalse;
for (i=0; i<RARRAY(ary1)->len; i++) {
if (!rb_eql(RARRAY(ary1)->ptr[i], RARRAY(ary2)->ptr[i]))
@@ -1898,7 +1892,6 @@ Init_Array()
rb_define_method(rb_cArray, "==", rb_ary_equal, 1);
rb_define_method(rb_cArray, "eql?", rb_ary_eql, 1);
rb_define_method(rb_cArray, "hash", rb_ary_hash, 0);
- rb_define_method(rb_cArray, "===", rb_ary_equal, 1);
rb_define_method(rb_cArray, "[]", rb_ary_aref, -1);
rb_define_method(rb_cArray, "[]=", rb_ary_aset, -1);
diff --git a/numeric.c b/numeric.c
index 57aeadc..646f9ba 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1723,7 +1723,6 @@ Init_Numeric()
rb_define_method(rb_cNumeric, "+@", num_uplus, 0);
rb_define_method(rb_cNumeric, "-@", num_uminus, 0);
- rb_define_method(rb_cNumeric, "===", num_equal, 1);
rb_define_method(rb_cNumeric, "<=>", num_cmp, 1);
rb_define_method(rb_cNumeric, "eql?", num_eql, 1);
rb_define_method(rb_cNumeric, "quo", num_quo, 1);
diff --git a/object.c b/object.c
index befbfe2..7a59abe 100644
--- a/object.c
+++ b/object.c
@@ -1314,7 +1314,7 @@ Init_Object()
rb_define_method(rb_mKernel, "nil?", rb_false, 0);
rb_define_method(rb_mKernel, "==", rb_obj_equal, 1);
rb_define_method(rb_mKernel, "equal?", rb_obj_equal, 1);
- rb_define_method(rb_mKernel, "===", rb_obj_equal, 1);
+ rb_define_method(rb_mKernel, "===", rb_equal, 1);
rb_define_method(rb_mKernel, "=~", rb_false, 1);
rb_define_method(rb_mKernel, "eql?", rb_obj_equal, 1);
diff --git a/re.c b/re.c
index dbf9bdf..9b78681 100644
--- a/re.c
+++ b/re.c
@@ -1225,47 +1225,68 @@ rb_reg_initialize_m(argc, argv, self)
VALUE *argv;
VALUE self;
{
- VALUE src;
+ const char *s;
+ long len;
int flags = 0;
+ rb_check_frozen(self);
if (argc == 0 || argc > 3) {
rb_raise(rb_eArgError, "wrong number of argument");
}
- if (argc >= 2) {
- if (FIXNUM_P(argv[1])) flags = FIX2INT(argv[1]);
- else if (RTEST(argv[1])) flags = RE_OPTION_IGNORECASE;
- }
- if (argc == 3) {
- char *kcode = StringValuePtr(argv[2]);
-
- switch (kcode[0]) {
- case 'n': case 'N':
+ if (TYPE(argv[0]) == T_REGEXP) {
+ if (argc > 1) {
+ rb_warn("flags%s ignored", (argc == 3) ? " and encoding": "");
+ }
+ rb_reg_check(argv[0]);
+ flags = RREGEXP(argv[0])->ptr->options & 0xf;
+ switch (RBASIC(argv[0])->flags & KCODE_MASK) {
+ case KCODE_NONE:
flags |= 16;
break;
- case 'e': case 'E':
+ case KCODE_EUC:
flags |= 32;
break;
- case 's': case 'S':
+ case KCODE_SJIS:
flags |= 48;
break;
- case 'u': case 'U':
+ case KCODE_UTF8:
flags |= 64;
break;
default:
break;
}
- }
-
- rb_check_frozen(self);
- src = argv[0];
- if (TYPE(src) == T_REGEXP) {
- rb_reg_check(src);
- rb_reg_initialize(self, RREGEXP(src)->str, RREGEXP(src)->len, flags);
+ s = RREGEXP(argv[0])->str;
+ len = RREGEXP(argv[0])->len;
}
else {
- StringValue(src);
- rb_reg_initialize(self, RSTRING(src)->ptr, RSTRING(src)->len, flags);
+ s = StringValuePtr(argv[0]);
+ len = RREGEXP(argv[0])->len;
+ if (argc >= 2) {
+ if (FIXNUM_P(argv[1])) flags = FIX2INT(argv[1]);
+ else if (RTEST(argv[1])) flags = RE_OPTION_IGNORECASE;
+ }
+ else if (argc == 3) {
+ char *kcode = StringValuePtr(argv[2]);
+
+ switch (kcode[0]) {
+ case 'n': case 'N':
+ flags |= 16;
+ break;
+ case 'e': case 'E':
+ flags |= 32;
+ break;
+ case 's': case 'S':
+ flags |= 48;
+ break;
+ case 'u': case 'U':
+ flags |= 64;
+ break;
+ default:
+ break;
+ }
+ }
}
+ rb_reg_initialize(self, s, len, flags);
return self;
}
diff --git a/string.c b/string.c
index 9044902..1b7c215 100644
--- a/string.c
+++ b/string.c
@@ -773,13 +773,9 @@ rb_str_equal(str1, str2)
VALUE str1, str2;
{
if (str1 == str2) return Qtrue;
- if (TYPE(str2) != T_STRING) {
- str2 = rb_check_string_type(str2);
- if (NIL_P(str2)) return Qfalse;
- }
-
- if (RSTRING(str1)->len == RSTRING(str2)->len
- && rb_str_cmp(str1, str2) == 0) {
+ if (TYPE(str2) != T_STRING) return Qfalse;
+ if (RSTRING(str1)->len == RSTRING(str2)->len &&
+ rb_str_cmp(str1, str2) == 0) {
return Qtrue;
}
return Qfalse;
@@ -3194,7 +3190,6 @@ Init_String()
rb_define_method(rb_cString, "copy_object", rb_str_replace, 1);
rb_define_method(rb_cString, "<=>", rb_str_cmp_m, 1);
rb_define_method(rb_cString, "==", rb_str_equal, 1);
- rb_define_method(rb_cString, "===", rb_str_equal, 1);
rb_define_method(rb_cString, "eql?", rb_str_eql, 1);
rb_define_method(rb_cString, "hash", rb_str_hash_m, 0);
rb_define_method(rb_cString, "casecmp", rb_str_casecmp, 1);