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

ruby-changes:42933

From: naruse <ko1@a...>
Date: Sun, 15 May 2016 16:17:50 +0900 (JST)
Subject: [ruby-changes:42933] naruse:r55007 (trunk): * array.c (rb_ary_entry): extract rb_ary_elt to organize if-conditions

naruse	2016-05-15 16:17:46 +0900 (Sun, 15 May 2016)

  New Revision: 55007

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

  Log:
    * array.c (rb_ary_entry): extract rb_ary_elt to organize if-conditions
      and check whether is is embdeded at once.

  Modified files:
    trunk/ChangeLog
    trunk/array.c
Index: array.c
===================================================================
--- array.c	(revision 55006)
+++ array.c	(revision 55007)
@@ -1195,10 +1195,17 @@ rb_ary_elt(VALUE ary, long offset) https://github.com/ruby/ruby/blob/trunk/array.c#L1195
 VALUE
 rb_ary_entry(VALUE ary, long offset)
 {
+    long len = RARRAY_LEN(ary);
+    const VALUE *ptr = RARRAY_CONST_PTR(ary);
+    if (len == 0) return Qnil;
     if (offset < 0) {
-	offset += RARRAY_LEN(ary);
+        offset += len;
+        if (offset < 0) return Qnil;
     }
-    return rb_ary_elt(ary, offset);
+    else if (len <= offset) {
+        return Qnil;
+    }
+    return ptr[offset];
 }
 
 VALUE
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55006)
+++ ChangeLog	(revision 55007)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun May 15 16:15:25 2016  NARUSE, Yui  <naruse@r...>
+
+	* array.c (rb_ary_entry): extract rb_ary_elt to organize if-conditions
+	  and check whether is is embdeded at once.
+
 Sun May 15 10:57:26 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* vm_insnhelper.c (vm_get_ev_const): warn deprecated constant even

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

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