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

ruby-changes:25422

From: shirosaki <ko1@a...>
Date: Tue, 6 Nov 2012 00:24:21 +0900 (JST)
Subject: [ruby-changes:25422] shirosaki:r37478 (trunk): Expose whether two arrays are shared

shirosaki	2012-11-06 00:24:07 +0900 (Tue, 06 Nov 2012)

  New Revision: 37478

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

  Log:
    Expose whether two arrays are shared
    
    * array.c (rb_ary_shared_with_p): new function.
      Expose whether two arrays are shared (read-only, C only).
    
    * include/ruby/intern.h (rb_ary_shared_with_p): declare.
      Patch by Greg Price.
      [ruby-core:47970] [Bug #7158]

  Modified files:
    trunk/ChangeLog
    trunk/array.c
    trunk/include/ruby/intern.h
    trunk/load.c

Index: array.c
===================================================================
--- array.c	(revision 37477)
+++ array.c	(revision 37478)
@@ -305,6 +305,22 @@
     return Qfalse;
 }
 
+/* This can be used to take a snapshot of an array (with
+   e.g. rb_ary_replace) and check later whether the array has been
+   modified from the snapshot.  The snapshot is cheap, though if
+   something does modify the array it will pay the cost of copying
+   it. */
+VALUE
+rb_ary_shared_with_p(VALUE ary1, VALUE ary2)
+{
+    if (!ARY_EMBED_P(ary1) && ARY_SHARED_P(ary1)
+     && !ARY_EMBED_P(ary2) && ARY_SHARED_P(ary2)
+     && RARRAY(ary1)->as.heap.aux.shared == RARRAY(ary2)->as.heap.aux.shared) {
+	return Qtrue;
+    }
+    return Qfalse;
+}
+
 static VALUE
 ary_alloc(VALUE klass)
 {
Index: include/ruby/intern.h
===================================================================
--- include/ruby/intern.h	(revision 37477)
+++ include/ruby/intern.h	(revision 37478)
@@ -56,6 +56,7 @@
 void rb_ary_free(VALUE);
 void rb_ary_modify(VALUE);
 VALUE rb_ary_freeze(VALUE);
+VALUE rb_ary_shared_with_p(VALUE, VALUE);
 VALUE rb_ary_aref(int, VALUE*, VALUE);
 VALUE rb_ary_subseq(VALUE, long, long);
 void rb_ary_store(VALUE, long, VALUE);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37477)
+++ ChangeLog	(revision 37478)
@@ -1,3 +1,12 @@
+Mon Nov  5 23:23:51 2012  Greg Price  <price@m...>
+
+	* array.c (rb_ary_shared_with_p): new function.
+	  Expose whether two arrays are shared (read-only, C only).
+
+	* include/ruby/intern.h (rb_ary_shared_with_p): declare.
+	  Patch by Greg Price.
+	  [ruby-core:47970] [Bug #7158]
+
 Mon Nov  5 23:21:14 2012  Greg Price  <price@m...>
 
 	* load.c (loaded_feature_path): clarify and briefly comment
Index: load.c
===================================================================
--- load.c	(revision 37477)
+++ load.c	(revision 37478)
@@ -88,7 +88,7 @@
     long plen;
     const char *e;
 
-    if (vlen < len+1) return 0
+    if (vlen < len+1) return 0;
     if (!strncmp(name+(vlen-len), feature, len)) {
 	plen = vlen - len - 1;
     }

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

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