summaryrefslogtreecommitdiffstats
path: root/string.c
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
commit55b1327d1b1ab126eca4bdf52ee817f08357530d (patch)
treef261aefbaa3b0909e36946925be65178e0921612 /string.c
parent148743016f1fc68a9d419696085831e279fc70fb (diff)
downloadruby-55b1327d1b1ab126eca4bdf52ee817f08357530d.tar.gz
ruby-55b1327d1b1ab126eca4bdf52ee817f08357530d.tar.xz
ruby-55b1327d1b1ab126eca4bdf52ee817f08357530d.zip
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@15441 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/string.c b/string.c
index 3d7d96266..ade00a3d2 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);