* 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:
parent
ff15c72d69
commit
38694016bc
10
ChangeLog
10
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>
|
Tue Feb 12 12:13:25 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* instruby.rb: specify file mode to install. a patch from
|
* instruby.rb: specify file mode to install. a patch from
|
||||||
|
2
hash.c
2
hash.c
@ -53,7 +53,7 @@ rb_any_cmp(VALUE a, VALUE b)
|
|||||||
}
|
}
|
||||||
if (TYPE(a) == T_STRING && RBASIC(a)->klass == rb_cString &&
|
if (TYPE(a) == T_STRING && RBASIC(a)->klass == rb_cString &&
|
||||||
TYPE(b) == T_STRING && RBASIC(b)->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 (a == Qundef || b == Qundef) return -1;
|
||||||
if (SYMBOL_P(a) && SYMBOL_P(b)) {
|
if (SYMBOL_P(a) && SYMBOL_P(b)) {
|
||||||
|
@ -528,6 +528,7 @@ VALUE rb_str_append(VALUE, VALUE);
|
|||||||
VALUE rb_str_concat(VALUE, VALUE);
|
VALUE rb_str_concat(VALUE, VALUE);
|
||||||
int rb_memhash(const void *ptr, long len);
|
int rb_memhash(const void *ptr, long len);
|
||||||
int rb_str_hash(VALUE);
|
int rb_str_hash(VALUE);
|
||||||
|
int rb_str_hash_cmp(VALUE,VALUE);
|
||||||
int rb_str_comparable(VALUE, VALUE);
|
int rb_str_comparable(VALUE, VALUE);
|
||||||
int rb_str_cmp(VALUE, VALUE);
|
int rb_str_cmp(VALUE, VALUE);
|
||||||
VALUE rb_str_equal(VALUE str1, VALUE str2);
|
VALUE rb_str_equal(VALUE str1, VALUE str2);
|
||||||
|
2
parse.y
2
parse.y
@ -8749,7 +8749,7 @@ static struct symbols {
|
|||||||
} global_symbols = {tLAST_TOKEN >> ID_SCOPE_SHIFT};
|
} global_symbols = {tLAST_TOKEN >> ID_SCOPE_SHIFT};
|
||||||
|
|
||||||
static const struct st_hash_type symhash = {
|
static const struct st_hash_type symhash = {
|
||||||
rb_str_cmp,
|
rb_str_hash_cmp,
|
||||||
rb_str_hash,
|
rb_str_hash,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
15
string.c
15
string.c
@ -1512,6 +1512,19 @@ rb_str_hash(VALUE str)
|
|||||||
return hash((const void *)RSTRING_PTR(str), RSTRING_LEN(str), 0);
|
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:
|
* call-seq:
|
||||||
* str.hash => fixnum
|
* str.hash => fixnum
|
||||||
@ -1700,7 +1713,7 @@ rb_str_casecmp(VALUE str1, VALUE str2)
|
|||||||
StringValue(str2);
|
StringValue(str2);
|
||||||
enc = rb_enc_compatible(str1, str2);
|
enc = rb_enc_compatible(str1, str2);
|
||||||
if (!enc) {
|
if (!enc) {
|
||||||
return rb_str_cmp(str1, str2);
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
p1 = RSTRING_PTR(str1); p1end = RSTRING_END(str1);
|
p1 = RSTRING_PTR(str1); p1end = RSTRING_END(str1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user