1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
matz 2008-02-12 03:17:43 +00:00
parent ff15c72d69
commit 38694016bc
5 changed files with 27 additions and 3 deletions

View file

@ -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

2
hash.c
View file

@ -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)) {

View file

@ -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);

View file

@ -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,
};

View file

@ -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);