diff options
| author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-02-12 03:17:43 +0000 |
|---|---|---|
| committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-02-12 03:17:43 +0000 |
| commit | 55b1327d1b1ab126eca4bdf52ee817f08357530d (patch) | |
| tree | f261aefbaa3b0909e36946925be65178e0921612 /string.c | |
| parent | 148743016f1fc68a9d419696085831e279fc70fb (diff) | |
| download | ruby-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.c | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -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); |
