aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--hash.c46
-rw-r--r--object.c4
-rw-r--r--string.c3
4 files changed, 36 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index 0c2b43dc75..c5f4fe0bae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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,
diff --git a/hash.c b/hash.c
index e852570183..07d88a7d66 100644
--- a/hash.c
+++ b/hash.c
@@ -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)
{
diff --git a/object.c b/object.c
index 4610070a3c..f6f764af7f 100644
--- a/object.c
+++ b/object.c
@@ -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:
diff --git a/string.c b/string.c
index 026ebd7147..2001724642 100644
--- a/string.c
+++ b/string.c
@@ -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);