mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
4d414c9f68
commit
e575070f2f
4 changed files with 27 additions and 1 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
Mon Nov 5 23:23:51 2012 Greg Price <price@mit.edu>
|
||||||
|
|
||||||
|
* 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@mit.edu>
|
Mon Nov 5 23:21:14 2012 Greg Price <price@mit.edu>
|
||||||
|
|
||||||
* load.c (loaded_feature_path): clarify and briefly comment
|
* load.c (loaded_feature_path): clarify and briefly comment
|
||||||
|
|
16
array.c
16
array.c
|
@ -305,6 +305,22 @@ rb_ary_frozen_p(VALUE ary)
|
||||||
return Qfalse;
|
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
|
static VALUE
|
||||||
ary_alloc(VALUE klass)
|
ary_alloc(VALUE klass)
|
||||||
{
|
{
|
||||||
|
|
|
@ -56,6 +56,7 @@ VALUE rb_ary_tmp_new(long);
|
||||||
void rb_ary_free(VALUE);
|
void rb_ary_free(VALUE);
|
||||||
void rb_ary_modify(VALUE);
|
void rb_ary_modify(VALUE);
|
||||||
VALUE rb_ary_freeze(VALUE);
|
VALUE rb_ary_freeze(VALUE);
|
||||||
|
VALUE rb_ary_shared_with_p(VALUE, VALUE);
|
||||||
VALUE rb_ary_aref(int, VALUE*, VALUE);
|
VALUE rb_ary_aref(int, VALUE*, VALUE);
|
||||||
VALUE rb_ary_subseq(VALUE, long, long);
|
VALUE rb_ary_subseq(VALUE, long, long);
|
||||||
void rb_ary_store(VALUE, long, VALUE);
|
void rb_ary_store(VALUE, long, VALUE);
|
||||||
|
|
2
load.c
2
load.c
|
@ -88,7 +88,7 @@ loaded_feature_path(const char *name, long vlen, const char *feature, long len,
|
||||||
long plen;
|
long plen;
|
||||||
const char *e;
|
const char *e;
|
||||||
|
|
||||||
if (vlen < len+1) return 0
|
if (vlen < len+1) return 0;
|
||||||
if (!strncmp(name+(vlen-len), feature, len)) {
|
if (!strncmp(name+(vlen-len), feature, len)) {
|
||||||
plen = vlen - len - 1;
|
plen = vlen - len - 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue