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

ruby-changes:42903

From: tarui <ko1@a...>
Date: Thu, 12 May 2016 00:04:32 +0900 (JST)
Subject: [ruby-changes:42903] tarui:r54977 (trunk): * vm_insnhelper.c (vm_getivar): describe fast-path explicit

tarui	2016-05-12 00:04:27 +0900 (Thu, 12 May 2016)

  New Revision: 54977

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

  Log:
    * vm_insnhelper.c (vm_getivar): describe fast-path explicit
      (compiler frindly). [Bug #12274].

  Modified files:
    trunk/ChangeLog
    trunk/vm_insnhelper.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54976)
+++ ChangeLog	(revision 54977)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed May 11 23:59:47 2016  Masaya Tarui  <tarui@r...>
+
+	* vm_insnhelper.c (vm_getivar): describe fast-path explicit
+	  (compiler frindly). [Bug #12274].
+
 Wed May 11 21:30:07 2016  Masaya Tarui  <tarui@r...>
 
 	* compile.c (iseq_compile_each): share InlineCache during same
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 54976)
+++ vm_insnhelper.c	(revision 54977)
@@ -785,18 +785,20 @@ INLINE VALUE https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L785
 vm_getivar(VALUE obj, ID id, IC ic, struct rb_call_cache *cc, int is_attr)
 {
 #if USE_IC_FOR_IVAR
-    if (RB_TYPE_P(obj, T_OBJECT)) {
+    if (LIKELY(RB_TYPE_P(obj, T_OBJECT))) {
 	VALUE val = Qundef;
-	VALUE klass = RBASIC(obj)->klass;
-	const uint32_t len = ROBJECT_NUMIV(obj);
-	const VALUE *const ptr = ROBJECT_IVPTR(obj);
-
-	if (LIKELY(is_attr ? cc->aux.index > 0 : ic->ic_serial == RCLASS_SERIAL(klass))) {
+	if (LIKELY(is_attr ? cc->aux.index > 0 : ic->ic_serial == RCLASS_SERIAL(RBASIC(obj)->klass))) {
 	    st_index_t index = !is_attr ? ic->ic_value.index : (cc->aux.index - 1);
-
-	    if (index < len) {
-		val = ptr[index];
+	    if (LIKELY(index < ROBJECT_NUMIV(obj))) {
+		val = ROBJECT_IVPTR(obj)[index];
+	    }
+	  undef_check:
+	    if (UNLIKELY(val == Qundef)) {
+		if (!is_attr && RTEST(ruby_verbose))
+		    rb_warning("instance variable %"PRIsVALUE" not initialized", QUOTE_ID(id));
+		val = Qnil;
 	    }
+	    return val;
 	}
 	else {
 	    st_data_t index;
@@ -804,26 +806,20 @@ vm_getivar(VALUE obj, ID id, IC ic, stru https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L806
 
 	    if (iv_index_tbl) {
 		if (st_lookup(iv_index_tbl, id, &index)) {
-		    if (index < len) {
-			val = ptr[index];
+		    if (index < ROBJECT_NUMIV(obj)) {
+			val = ROBJECT_IVPTR(obj)[index];
 		    }
 		    if (!is_attr) {
 			ic->ic_value.index = index;
-			ic->ic_serial = RCLASS_SERIAL(klass);
+			ic->ic_serial = RCLASS_SERIAL(RBASIC(obj)->klass);
 		    }
 		    else { /* call_info */
 			cc->aux.index = (int)index + 1;
 		    }
 		}
 	    }
+	    goto undef_check;
 	}
-
-	if (UNLIKELY(val == Qundef)) {
-	    if (!is_attr && RTEST(ruby_verbose))
-		rb_warning("instance variable %"PRIsVALUE" not initialized", QUOTE_ID(id));
-	    val = Qnil;
-	}
-	return val;
     }
 #endif	/* USE_IC_FOR_IVAR */
     if (is_attr)
@@ -837,7 +833,7 @@ vm_setivar(VALUE obj, ID id, VALUE val, https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L833
 #if USE_IC_FOR_IVAR
     rb_check_frozen(obj);
 
-    if (RB_TYPE_P(obj, T_OBJECT)) {
+    if (LIKELY(RB_TYPE_P(obj, T_OBJECT))) {
 	VALUE klass = RBASIC(obj)->klass;
 	st_data_t index;
 
@@ -874,13 +870,13 @@ vm_setivar(VALUE obj, ID id, VALUE val, https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L870
     return rb_ivar_set(obj, id, val);
 }
 
-static VALUE
+static inline VALUE
 vm_getinstancevariable(VALUE obj, ID id, IC ic)
 {
     return vm_getivar(obj, id, ic, 0, 0);
 }
 
-static void
+static inline void
 vm_setinstancevariable(VALUE obj, ID id, VALUE val, IC ic)
 {
     vm_setivar(obj, id, val, ic, 0, 0);

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

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