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

ruby-changes:17506

From: ko1 <ko1@a...>
Date: Sat, 16 Oct 2010 00:23:23 +0900 (JST)
Subject: [ruby-changes:17506] Ruby:r29511 (trunk): * hash.c (rb_hash_aref): skip calling "default" method

ko1	2010-10-16 00:10:17 +0900 (Sat, 16 Oct 2010)

  New Revision: 29511

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

  Log:
    * hash.c (rb_hash_aref): skip calling "default" method
      if it is not neede for speed-up.

  Modified files:
    trunk/ChangeLog
    trunk/hash.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 29510)
+++ ChangeLog	(revision 29511)
@@ -1,3 +1,8 @@
+Sat Oct 16 00:08:00 2010  Koichi Sasada  <ko1@a...>
+
+	* hash.c (rb_hash_aref): skip calling "default" method
+	  if it is not neede for speed-up.
+
 Fri Oct 15 23:36:25 2010  Nobuyoshi Nakada  <nobu@r...>
 
 	* file.c (NUM2DEVT, DEVT2NUM, PRI_DEVT_PREFIX): fallback to
Index: hash.c
===================================================================
--- hash.c	(revision 29510)
+++ hash.c	(revision 29511)
@@ -509,7 +509,14 @@
     st_data_t val;
 
     if (!RHASH(hash)->ntbl || !st_lookup(RHASH(hash)->ntbl, key, &val)) {
-	return rb_funcall(hash, id_default, 1, key);
+	int rb_method_basic_definition_p(VALUE klass, ID id);
+	if (!FL_TEST(hash, HASH_PROC_DEFAULT) &&
+	    rb_method_basic_definition_p(CLASS_OF(hash), id_default)) {
+	    return RHASH_IFNONE(hash);
+	}
+	else {
+	    return rb_funcall(hash, id_default, 1, key);
+	}
     }
     return (VALUE)val;
 }

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

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