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 | 38694016bc226abd074c239282dc047ad7c65c55 (patch) | |
tree | f261aefbaa3b0909e36946925be65178e0921612 | |
parent | ff15c72d694a8bb9d5ad40d14dc5d8f1fee419e0 (diff) | |
download | ruby-38694016bc226abd074c239282dc047ad7c65c55.tar.gz |
* 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-- | ChangeLog | 10 | ||||
-rw-r--r-- | hash.c | 2 | ||||
-rw-r--r-- | include/ruby/intern.h | 1 | ||||
-rw-r--r-- | parse.y | 2 | ||||
-rw-r--r-- | string.c | 15 |
5 files changed, 27 insertions, 3 deletions
@@ -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 @@ -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); @@ -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, }; @@ -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); |