Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Last fixes to get MRI test_array green on packed arrays.
Browse files Browse the repository at this point in the history
headius committed Jun 20, 2016
1 parent e1c89ce commit 2bfa81c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -443,6 +443,9 @@ public IRubyObject[] toJavaArrayMaybeUnsafe() {
*
*/
private RubyArray makeShared() {
// TODO: (CON) Some calls to makeShared could create packed array almost as efficiently
unpack();

return makeShared(begin, realLength, getMetaClass());
}

@@ -2898,6 +2901,7 @@ public IRubyObject rassoc(ThreadContext context, IRubyObject value) {

// MRI array.c flatten
protected boolean flatten(ThreadContext context, final int level, final RubyArray result) {
// TODO: (CON) We can flatten packed versions efficiently if length does not change (e.g. [[1,2],[]])
unpack();
final Ruby runtime = context.runtime;
RubyArray stack = newArrayLight(runtime, ARRAY_DEFAULT_SIZE);
@@ -3151,6 +3155,9 @@ public IRubyObject uniq_bang(ThreadContext context) {
RubyHash hash = makeHash();
if (realLength == hash.size()) return context.runtime.getNil();

// TODO: (CON) This could be a no-op for packed arrays if size does not change
unpack();

int j = 0;
for (int i = 0; i < realLength; i++) {
IRubyObject v = elt(i);
@@ -3167,6 +3174,10 @@ public IRubyObject uniq_bang19(ThreadContext context, Block block) {
if (!block.isGiven()) return uniq_bang(context);
RubyHash hash = makeHash(context, block);
if (realLength == hash.size()) return context.runtime.getNil();

// TODO: (CON) This could be a no-op for packed arrays if size does not change
unpack();

realLength = 0;

hash.visitAll(new RubyHash.Visitor() {

0 comments on commit 2bfa81c

Please sign in to comment.