Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: da5e0863d293
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d1de0a09c6cb
Choose a head ref
  • 3 commits
  • 6 files changed
  • 1 contributor

Commits on Feb 6, 2015

  1. Copy the full SHA
    ccfa2af View commit details
  2. Copy the full SHA
    4236e2e View commit details
  3. Copy the full SHA
    d1de0a0 View commit details
4 changes: 0 additions & 4 deletions spec/truffle/tags/core/array/eql_tags.txt

This file was deleted.

4 changes: 0 additions & 4 deletions spec/truffle/tags/core/array/equal_value_tags.txt

This file was deleted.

265 changes: 0 additions & 265 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -261,200 +261,6 @@ public RubyArray mulObject(RubyArray array, int count) {

}

@CoreMethod(names = "|", required = 1)
public abstract static class UnionNode extends ArrayCoreMethodNode {

public UnionNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public UnionNode(UnionNode prev) {
super(prev);
}

@Specialization(guards = "areBothIntegerFixnum")
public RubyArray orIntegerFixnum(RubyArray a, RubyArray b) {
notDesignedForCompilation();

final int[] as = (int[]) a.getStore();
final int[] bs = (int[]) b.getStore();

final int[] or = Arrays.copyOf(as, a.getSize() + b.getSize());

int i = a.getSize();

for (int n = 0; n < b.getSize(); n++) {
if (!ArrayUtils.contains(as, bs[n])) {
or[i] = bs[n];
i++;
}
}

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), or, i);
}

@Specialization(guards = "areBothLongFixnum")
public RubyArray orLongFixnum(RubyArray a, RubyArray b) {
notDesignedForCompilation();

final long[] as = (long[]) a.getStore();
final long[] bs = (long[]) b.getStore();

final long[] or = Arrays.copyOf(as, a.getSize() + b.getSize());

int i = a.getSize();

for (int n = 0; n < b.getSize(); n++) {
if (!ArrayUtils.contains(as, bs[n])) {
or[i] = bs[n];
i++;
}
}

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), or, i);
}

@Specialization(guards = "areBothFloat")
public RubyArray orDouble(RubyArray a, RubyArray b) {
notDesignedForCompilation();

final double[] as = (double[]) a.getStore();
final double[] bs = (double[]) b.getStore();

final double[] or = Arrays.copyOf(as, a.getSize() + b.getSize());

int i = a.getSize();

for (int n = 0; n < b.getSize(); n++) {
if (!ArrayUtils.contains(as, bs[n])) {
or[i] = bs[n];
i++;
}
}

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), or, i);
}

@Specialization(guards = "areBothObject")
public RubyArray orObject(RubyArray a, RubyArray b) {
notDesignedForCompilation();

final Object[] as = (Object[]) a.getStore();
final Object[] bs = (Object[]) b.getStore();

final Object[] or = Arrays.copyOf(as, a.getSize() + b.getSize());

int i = a.getSize();

for (int n = 0; n < b.getSize(); n++) {
if (!ArrayUtils.contains(as, a.getSize(), bs[n])) {
or[i] = bs[n];
i++;
}
}

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), or, i);
}

}

@CoreMethod(names = {"==", "eql?"}, required = 1)
public abstract static class EqualNode extends ArrayCoreMethodNode {

@Child private CallDispatchHeadNode equals;

public EqualNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
equals = DispatchHeadNodeFactory.createMethodCall(context, false, false, null);
}

public EqualNode(EqualNode prev) {
super(prev);
equals = prev.equals;
}

@Specialization(guards = "areBothIntegerFixnum")
public boolean equalIntegerFixnum(RubyArray a, RubyArray b) {
notDesignedForCompilation();

if (a == b) {
return true;
}

if (a.getSize() != b.getSize()) {
return false;
}

return Arrays.equals((int[]) a.getStore(), (int[]) b.getStore());
}

@Specialization(guards = "areBothLongFixnum")
public boolean equalLongFixnum(RubyArray a, RubyArray b) {
notDesignedForCompilation();

if (a == b) {
return true;
}

if (a.getSize() != b.getSize()) {
return false;
}

return Arrays.equals((long[]) a.getStore(), (long[]) b.getStore());
}

@Specialization(guards = "areBothFloat")
public boolean equalFloat(RubyArray a, RubyArray b) {
notDesignedForCompilation();

if (a == b) {
return true;
}

if (a.getSize() != b.getSize()) {
return false;
}

return Arrays.equals((double[]) a.getStore(), (double[]) b.getStore());
}

@Specialization
public boolean equal(VirtualFrame frame, RubyArray a, RubyArray b) {
notDesignedForCompilation();

if (a == b) {
return true;
}

if (a.getSize() != b.getSize()) {
return false;
}

final Object[] as = a.slowToArray();
final Object[] bs = b.slowToArray();

for (int n = 0; n < a.getSize(); n++) {
if (!equals.callBoolean(frame, as[n], "==", null, bs[n])) {
return false;
}
}

return true;
}

@Specialization
public boolean equal(VirtualFrame frame, RubyArray a, Object b) {
notDesignedForCompilation();

if (!(b instanceof RubyArray)) {
return false;
} else {
return equal(frame, a, (RubyArray) b);
}
}

}

@CoreMethod(names = "at", required = 1, lowerFixnumParameters = 0)
public abstract static class AtNode extends ArrayCoreMethodNode {

@@ -1078,77 +884,6 @@ public RubyArray setIntegerFixnumRange(RubyArray array, RubyRange.IntegerFixnumR

}

@CoreMethod(names = "any?", needsBlock = true)
@ImportGuards(ArrayGuards.class)
public abstract static class AnyNode extends YieldingCoreMethodNode {

public AnyNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public AnyNode(AnyNode prev) {
super(prev);
}

@Specialization(guards = "isNull")
public boolean anyNull(VirtualFrame frame, RubyArray array, RubyProc block) {
return false;
}

@Specialization(guards = "isIntegerFixnum")
public boolean allIntegerFixnum(VirtualFrame frame, RubyArray array, RubyProc block) {
notDesignedForCompilation();

for (int n = 0; n < array.getSize(); n++) {
if (yieldIsTruthy(frame, block, ((int[]) array.getStore())[n])) {
return true;
}
}

return false;
}

@Specialization(guards = "isLongFixnum")
public boolean anyLongFixnum(VirtualFrame frame, RubyArray array, RubyProc block) {
notDesignedForCompilation();

for (int n = 0; n < array.getSize(); n++) {
if (yieldIsTruthy(frame, block, ((long[]) array.getStore())[n])) {
return true;
}
}

return false;
}

@Specialization(guards = "isFloat")
public boolean anyFloat(VirtualFrame frame, RubyArray array, RubyProc block) {
notDesignedForCompilation();

for (int n = 0; n < array.getSize(); n++) {
if (yieldIsTruthy(frame, block, ((double[]) array.getStore())[n])) {
return true;
}
}

return false;
}

@Specialization(guards = "isObject")
public boolean anyObject(VirtualFrame frame, RubyArray array, RubyProc block) {
notDesignedForCompilation();

for (int n = 0; n < array.getSize(); n++) {
if (yieldIsTruthy(frame, block, ((Object[]) array.getStore())[n])) {
return true;
}
}

return false;
}

}

@CoreMethod(names = "clear")
public abstract static class ClearNode extends ArrayCoreMethodNode {

Original file line number Diff line number Diff line change
@@ -1499,15 +1499,22 @@ public RubyNode visitInstVarNode(org.jruby.ast.InstVarNode node) {

/*
* Rubinius uses the instance variable @total to store the size of an array. In order to use code that
* expects that we'll replace it statically with a call to Array#size.
* expects that we'll replace it statically with a call to Array#size. We also replace @tuple with
* self, and @start to be 0.
*/

if (sourceSection.getSource().getPath().equals("core:/jruby/truffle/core/rubinius/kernel/common/array.rb") && nameWithoutSigil.equals("@total")) {
return new RubyCallNode(context, sourceSection,
"size",
new SelfNode(context, sourceSection),
null,
false);
if (sourceSection.getSource().getPath().equals("core:/jruby/truffle/core/rubinius/kernel/common/array.rb")) {
if (nameWithoutSigil.equals("@total")) {
return new RubyCallNode(context, sourceSection,
"size",
new SelfNode(context, sourceSection),
null,
false);
} else if (nameWithoutSigil.equals("@tuple")) {
return new SelfNode(context, sourceSection);
} else if (nameWithoutSigil.equals("@start")) {
return new FixnumLiteralNode.IntegerFixnumLiteralNode(context, sourceSection, 0);
}
}

final RubyNode receiver = new SelfNode(context, sourceSection);
Original file line number Diff line number Diff line change
@@ -22,6 +22,14 @@ def total
@array.size
end

def tuple
@array
end

def start
0
end

end
end
end
Original file line number Diff line number Diff line change
@@ -27,7 +27,8 @@
# Only part of Rubinius' array.rb

# Rubinius uses the instance variable @total to store the size. We replace this
# in the translator with a call to size.
# in the translator with a call to size. We also replace the instance variable
# @tuple to be self, and @start to be 0.

class Array

@@ -251,4 +252,57 @@ def -(other)
array
end

def |(other)
other = Rubinius::Type.coerce_to other, Array, :to_ary

im = Rubinius::IdentityMap.from self, other
im.to_array
end

def ==(other)
return true if equal?(other)
unless other.kind_of? Array
return false unless other.respond_to? :to_ary
return other == self
end

return false unless size == other.size

Thread.detect_recursion self, other do
m = Rubinius::Mirror::Array.reflect other

md = @tuple
od = m.tuple

i = @start
j = m.start

total = i + @total

while i < total
return false unless md[i] == od[j]
i += 1
j += 1
end
end

true
end

def eql?(other)
return true if equal? other
return false unless other.kind_of?(Array)
return false if @total != other.size

Thread.detect_recursion self, other do
i = 0
each do |x|
return false unless x.eql? other[i]
i += 1
end
end

true
end

end