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

ruby-changes:44667

From: nobu <ko1@a...>
Date: Sat, 12 Nov 2016 15:22:05 +0900 (JST)
Subject: [ruby-changes:44667] nobu:r56740 (trunk): pack.c: simplify

nobu	2016-11-12 15:12:13 +0900 (Sat, 12 Nov 2016)

  New Revision: 56740

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

  Log:
    pack.c: simplify
    
    * pack.c (str_associate): remove unnecessary branch.
      the argument must be a plain vanilla string object.
    
    * pack.c (str_associated): use rb_ivar_lookup to give the
      undefined value.

  Modified files:
    trunk/pack.c
Index: pack.c
===================================================================
--- pack.c	(revision 56739)
+++ pack.c	(revision 56740)
@@ -116,24 +116,14 @@ static ID id_associated; https://github.com/ruby/ruby/blob/trunk/pack.c#L116
 static void
 str_associate(VALUE str, VALUE add)
 {
-    VALUE assoc;
-
-    assoc = rb_attr_get(str, id_associated);
-    if (RB_TYPE_P(assoc, T_ARRAY)) {
-	/* already associated */
-	rb_ary_concat(assoc, add);
-    }
-    else {
-	rb_ivar_set(str, id_associated, add);
-    }
+    /* assert(NIL_P(rb_attr_get(str, id_associated))); */
+    rb_ivar_set(str, id_associated, add);
 }
 
 static VALUE
 str_associated(VALUE str)
 {
-    VALUE assoc = rb_attr_get(str, id_associated);
-    if (NIL_P(assoc)) assoc = Qfalse;
-    return assoc;
+    return rb_ivar_lookup(str, id_associated, Qfalse);
 }
 
 void

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

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