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

hash.c: move rb_obj_hash

* hash.c (rb_obj_hash): move in order to share with rb_any_hash.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-07-29 08:25:49 +00:00
parent 07900180ec
commit 987df2ece6
4 changed files with 36 additions and 21 deletions

View file

@ -1,3 +1,7 @@
Wed Jul 29 17:25:46 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* hash.c (rb_obj_hash): move in order to share with rb_any_hash.
Wed Jul 29 16:00:22 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (str_buf_cat): consider empty non-embed string case,

46
hash.c
View file

@ -129,23 +129,8 @@ rb_hash(VALUE obj)
long rb_objid_hash(st_index_t index);
VALUE
rb_sym_hash(VALUE sym)
{
st_index_t hnum;
if (STATIC_SYM_P(sym)) {
sym >>= (RUBY_SPECIAL_SHIFT + ID_SCOPE_SHIFT);
hnum = rb_objid_hash((st_index_t)sym);
}
else {
hnum = RSYMBOL(sym)->hashval;
}
return LONG2FIX(hnum);
}
static st_index_t
rb_any_hash(VALUE a)
any_hash(VALUE a, st_index_t (*other_func)(VALUE))
{
VALUE hval;
st_index_t hnum;
@ -173,13 +158,25 @@ rb_any_hash(VALUE a)
hnum = FIX2LONG(hval);
}
else {
hval = rb_hash(a);
hnum = FIX2LONG(hval);
hnum = other_func(a);
}
hnum <<= 1;
return (st_index_t)RSHIFT(hnum, 1);
}
static st_index_t
obj_any_hash(VALUE obj)
{
obj = rb_hash(obj);
return FIX2LONG(obj);
}
static st_index_t
rb_any_hash(VALUE a)
{
return any_hash(a, obj_any_hash);
}
long
rb_objid_hash(st_index_t index)
{
@ -189,6 +186,19 @@ rb_objid_hash(st_index_t index)
return hnum;
}
static st_index_t
objid_hash(VALUE obj)
{
return rb_objid_hash((st_index_t)obj);
}
VALUE
rb_obj_hash(VALUE obj)
{
st_index_t hnum = any_hash(obj, objid_hash);
return LONG2FIX(hnum);
}
int
rb_hash_iter_lev(VALUE h)
{

View file

@ -142,6 +142,7 @@ rb_obj_equal(VALUE obj1, VALUE obj2)
return Qfalse;
}
#if 0
/*
* call-seq:
* obj.hash -> fixnum
@ -171,6 +172,9 @@ rb_obj_hash(VALUE obj)
#endif
return LONG2FIX(rb_objid_hash(index));
}
#else
VALUE rb_obj_hash(VALUE obj);
#endif
/*
* call-seq:

View file

@ -9154,8 +9154,6 @@ rb_to_symbol(VALUE name)
return rb_str_intern(name);
}
VALUE rb_sym_hash(VALUE);
/*
* A <code>String</code> object holds and manipulates an arbitrary sequence of
* bytes, typically representing characters. String objects may be created
@ -9318,7 +9316,6 @@ Init_String(void)
rb_undef_method(CLASS_OF(rb_cSymbol), "new");
rb_define_singleton_method(rb_cSymbol, "all_symbols", rb_sym_all_symbols, 0); /* in symbol.c */
rb_define_method(rb_cSymbol, "hash", rb_sym_hash, 0); /* in hash.c */
rb_define_method(rb_cSymbol, "==", sym_equal, 1);
rb_define_method(rb_cSymbol, "===", sym_equal, 1);
rb_define_method(rb_cSymbol, "inspect", sym_inspect, 0);