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

ruby-changes:47829

From: mame <ko1@a...>
Date: Mon, 18 Sep 2017 08:56:43 +0900 (JST)
Subject: [ruby-changes:47829] mame:r59947 (trunk): ext/objspace/objspace.c: remove unneeded code clones.

mame	2017-09-18 08:56:37 +0900 (Mon, 18 Sep 2017)

  New Revision: 59947

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

  Log:
    ext/objspace/objspace.c: remove unneeded code clones.
    
    `setup_hash` have already performed nil check and empty check.

  Modified files:
    trunk/ext/objspace/objspace.c
    trunk/test/objspace/test_objspace.rb
Index: test/objspace/test_objspace.rb
===================================================================
--- test/objspace/test_objspace.rb	(revision 59946)
+++ test/objspace/test_objspace.rb	(revision 59947)
@@ -61,9 +61,19 @@ class TestObjSpace < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/objspace/test_objspace.rb#L61
     res = ObjectSpace.count_objects_size
     assert_not_empty(res)
     assert_operator(res[:TOTAL], :>, 0)
+  end
+
+  def test_count_objects_size_with_hash
     arg = {}
     ObjectSpace.count_objects_size(arg)
     assert_not_empty(arg)
+    arg = {:TOTAL => 1 }
+    ObjectSpace.count_objects_size(arg)
+    assert_not_empty(arg)
+  end
+
+  def test_count_objects_size_with_wrong_type
+    assert_raise(TypeError) { ObjectSpace.count_objects_size(0) }
   end
 
   def test_count_nodes
Index: ext/objspace/objspace.c
===================================================================
--- ext/objspace/objspace.c	(revision 59946)
+++ ext/objspace/objspace.c	(revision 59947)
@@ -203,7 +203,7 @@ type2sym(enum ruby_value_type i) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L203
  *
  *  Note that this information is incomplete.  You need to deal with
  *  this information as only a *HINT*.  Especially, total size of
- *  T_DATA may not right size.
+ *  T_DATA may be wrong.
  *
  *  It returns a hash as:
  *    {:TOTAL=>1461154, :T_CLASS=>158280, :T_MODULE=>20672, :T_STRING=>527249, ...}
@@ -232,13 +232,6 @@ count_objects_size(int argc, VALUE *argv https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L232
 
     rb_objspace_each_objects(cos_i, &counts[0]);
 
-    if (hash == Qnil) {
-        hash = rb_hash_new();
-    }
-    else if (!RHASH_EMPTY_P(hash)) {
-        st_foreach(RHASH_TBL(hash), set_zero_i, hash);
-    }
-
     for (i = 0; i <= T_MASK; i++) {
 	if (counts[i]) {
 	    VALUE type = type2sym(i);
@@ -313,13 +306,6 @@ count_symbols(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L306
     size_t immortal_symbols = rb_sym_immortal_count();
     rb_objspace_each_objects(cs_i, &dynamic_counts);
 
-    if (hash == Qnil) {
-        hash = rb_hash_new();
-    }
-    else if (!RHASH_EMPTY_P(hash)) {
-        st_foreach(RHASH_TBL(hash), set_zero_i, hash);
-    }
-
     rb_hash_aset(hash, ID2SYM(rb_intern("mortal_dynamic_symbol")),   SIZET2NUM(dynamic_counts.mortal));
     rb_hash_aset(hash, ID2SYM(rb_intern("immortal_dynamic_symbol")), SIZET2NUM(dynamic_counts.immortal));
     rb_hash_aset(hash, ID2SYM(rb_intern("immortal_static_symbol")),  SIZET2NUM(immortal_symbols - dynamic_counts.immortal));
@@ -380,13 +366,6 @@ count_nodes(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L366
 
     rb_objspace_each_objects(cn_i, &nodes[0]);
 
-    if (hash == Qnil) {
-        hash = rb_hash_new();
-    }
-    else if (!RHASH_EMPTY_P(hash)) {
-        st_foreach(RHASH_TBL(hash), set_zero_i, hash);
-    }
-
     for (i=0; i<NODE_LAST; i++) {
 	if (nodes[i] != 0) {
 	    VALUE node;

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

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