diff options
author | shirosaki <shirosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-05 15:24:07 +0000 |
---|---|---|
committer | shirosaki <shirosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-05 15:24:07 +0000 |
commit | e575070f2f513051d2937bf2f6031e400eb6a82e (patch) | |
tree | efb94f8dfffc36499b78109ed13f3a04c64b6476 /array.c | |
parent | 4d414c9f681a0a359df7686fef45bfd531ba634e (diff) | |
download | ruby-e575070f2f513051d2937bf2f6031e400eb6a82e.tar.gz |
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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37478 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -305,6 +305,22 @@ rb_ary_frozen_p(VALUE ary) 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) { |