summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-12 03:17:43 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-12 03:17:43 +0000
commit38694016bc226abd074c239282dc047ad7c65c55 (patch)
treef261aefbaa3b0909e36946925be65178e0921612
parentff15c72d694a8bb9d5ad40d14dc5d8f1fee419e0 (diff)
* string.c (rb_str_hash_cmp): lighter version of rb_str_cmp() for
hash comparison function. * hash.c (rb_any_cmp): use rb_str_hash_cmp(). * string.c (rb_str_casecmp): should return nil for incompatible comparison. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15441 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog10
-rw-r--r--hash.c2
-rw-r--r--include/ruby/intern.h1
-rw-r--r--parse.y2
-rw-r--r--string.c15
5 files changed, 27 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 77fa43870f..eac72fe206 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Tue Feb 12 12:16:45 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * string.c (rb_str_hash_cmp): lighter version of rb_str_cmp() for
+ hash comparison function.
+
+ * hash.c (rb_any_cmp): use rb_str_hash_cmp().
+
+ * string.c (rb_str_casecmp): should return nil for incompatible
+ comparison.
+
Tue Feb 12 12:13:25 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* instruby.rb: specify file mode to install. a patch from
diff --git a/hash.c b/hash.c
index 781beefc6b..53711b2cc2 100644
--- a/hash.c
+++ b/hash.c
@@ -53,7 +53,7 @@ rb_any_cmp(VALUE a, VALUE b)
}
if (TYPE(a) == T_STRING && RBASIC(a)->klass == rb_cString &&
TYPE(b) == T_STRING && RBASIC(b)->klass == rb_cString) {
- return rb_str_cmp(a, b);
+ return rb_str_hash_cmp(a, b);
}
if (a == Qundef || b == Qundef) return -1;
if (SYMBOL_P(a) && SYMBOL_P(b)) {
diff --git a/include/ruby/intern.h b/include/ruby/intern.h
index 80c3cd3815..dd259e8fe2 100644
--- a/include/ruby/intern.h
+++ b/include/ruby/intern.h
@@ -528,6 +528,7 @@ VALUE rb_str_append(VALUE, VALUE);
VALUE rb_str_concat(VALUE, VALUE);
int rb_memhash(const void *ptr, long len);
int rb_str_hash(VALUE);
+int rb_str_hash_cmp(VALUE,VALUE);
int rb_str_comparable(VALUE, VALUE);
int rb_str_cmp(VALUE, VALUE);
VALUE rb_str_equal(VALUE str1, VALUE str2);
diff --git a/parse.y b/parse.y
index 8ca7c86270..51e9136c60 100644
--- a/parse.y
+++ b/parse.y
@@ -8749,7 +8749,7 @@ static struct symbols {
} global_symbols = {tLAST_TOKEN >> ID_SCOPE_SHIFT};
static const struct st_hash_type symhash = {
- rb_str_cmp,
+ rb_str_hash_cmp,
rb_str_hash,
};
diff --git a/string.c b/string.c
index 3d7d962669..ade00a3d27 100644
--- a/string.c
+++ b/string.c
@@ -1512,6 +1512,19 @@ rb_str_hash(VALUE str)
return hash((const void *)RSTRING_PTR(str), RSTRING_LEN(str), 0);
}
+int
+rb_str_hash_cmp(VALUE str1, VALUE str2)
+{
+ int len;
+
+ if (!rb_str_comparable(str1, str2)) return 1;
+ if (RSTRING_LEN(str1) == (len = RSTRING_LEN(str2)) &&
+ memcmp(RSTRING_PTR(str1), RSTRING_PTR(str2), len) == 0) {
+ return 0;
+ }
+ return 1;
+}
+
/*
* call-seq:
* str.hash => fixnum
@@ -1700,7 +1713,7 @@ rb_str_casecmp(VALUE str1, VALUE str2)
StringValue(str2);
enc = rb_enc_compatible(str1, str2);
if (!enc) {
- return rb_str_cmp(str1, str2);
+ return Qnil;
}
p1 = RSTRING_PTR(str1); p1end = RSTRING_END(str1);