[前][次][番号順一覧][スレッド一覧]

ruby-changes:39349

From: nobu <ko1@a...>
Date: Wed, 29 Jul 2015 17:26:09 +0900 (JST)
Subject: [ruby-changes:39349] nobu:r51430 (trunk): hash.c: move rb_obj_hash

nobu	2015-07-29 17:25:49 +0900 (Wed, 29 Jul 2015)

  New Revision: 51430

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51430

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

  Modified files:
    trunk/ChangeLog
    trunk/hash.c
    trunk/object.c
    trunk/string.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51429)
+++ ChangeLog	(revision 51430)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jul 29 17:25:46 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* hash.c (rb_obj_hash): move in order to share with rb_any_hash.
+
 Wed Jul 29 16:00:22 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* string.c (str_buf_cat): consider empty non-embed string case,
Index: string.c
===================================================================
--- string.c	(revision 51429)
+++ string.c	(revision 51430)
@@ -9154,8 +9154,6 @@ rb_to_symbol(VALUE name) https://github.com/ruby/ruby/blob/trunk/string.c#L9154
     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) https://github.com/ruby/ruby/blob/trunk/string.c#L9316
     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);
Index: object.c
===================================================================
--- object.c	(revision 51429)
+++ object.c	(revision 51430)
@@ -142,6 +142,7 @@ rb_obj_equal(VALUE obj1, VALUE obj2) https://github.com/ruby/ruby/blob/trunk/object.c#L142
     return Qfalse;
 }
 
+#if 0
 /*
  * call-seq:
  *    obj.hash    -> fixnum
@@ -171,6 +172,9 @@ rb_obj_hash(VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L172
 #endif
     return LONG2FIX(rb_objid_hash(index));
 }
+#else
+VALUE rb_obj_hash(VALUE obj);
+#endif
 
 /*
  *  call-seq:
Index: hash.c
===================================================================
--- hash.c	(revision 51429)
+++ hash.c	(revision 51430)
@@ -129,23 +129,8 @@ rb_hash(VALUE obj) https://github.com/ruby/ruby/blob/trunk/hash.c#L129
 
 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) https://github.com/ruby/ruby/blob/trunk/hash.c#L158
 	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) https://github.com/ruby/ruby/blob/trunk/hash.c#L186
     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)
 {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]