Skip to content

Commit

Permalink
[Truffle] Divide up the large number of specialisations for array ind…
Browse files Browse the repository at this point in the history
…exing.
  • Loading branch information
chrisseaton committed Feb 4, 2015
1 parent 96e4133 commit 9da6ed4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Expand Up @@ -661,11 +661,15 @@ public IndexNode(IndexNode prev) {
fallbackNode = prev.fallbackNode;
}

// Simple indexing

@Specialization
public Object index(RubyArray array, int index, UndefinedPlaceholder undefined) {
return atNode.executeAt(array, index);
}

// Slice with two fixnums

@Specialization(guards = "isIntegerFixnum")
public Object sliceIntegerFixnum(RubyArray array, int start, int length) {
final int normalisedIndex = array.normaliseIndex(start);
Expand Down Expand Up @@ -722,6 +726,8 @@ public Object sliceObject(RubyArray array, int start, int length) {
}
}

// Slice with a range

@Specialization(guards = "isIntegerFixnum")
public Object sliceIntegerFixnum(RubyArray array, RubyRange.IntegerFixnumRange range, UndefinedPlaceholder undefined) {
notDesignedForCompilation();
Expand Down Expand Up @@ -802,6 +808,8 @@ public Object sliceObject(RubyArray array, RubyRange.IntegerFixnumRange range, U
}
}

// Fallbacks

@Specialization(guards = {"!isInteger(arguments[1])", "!isIntegerFixnumRange(arguments[1])"})
public Object sliceFallback(VirtualFrame frame, RubyArray array, Object a, UndefinedPlaceholder undefined) {
notDesignedForCompilation();
Expand Down Expand Up @@ -860,6 +868,8 @@ public IndexSetNode(IndexSetNode prev) {
super(prev);
}

// Set a simple index in an empty array

@Specialization(guards = "isNull")
public Object setNullIntegerFixnum(RubyArray array, int index, int value, UndefinedPlaceholder unused) {
if (index == 0) {
Expand Down Expand Up @@ -897,6 +907,8 @@ public Object setNullObject(RubyArray array, int index, Object value, UndefinedP
return value;
}

// Set a simple index in an existing array

@Specialization(guards = "isIntegerFixnum")
public int setIntegerFixnum(RubyArray array, int index, int value, UndefinedPlaceholder unused) {
final int normalisedIndex = array.normaliseIndex(index);
Expand Down Expand Up @@ -1106,6 +1118,8 @@ public Object setObject(RubyArray array, int index, Object value, UndefinedPlace
return value;
}

// Set a slice of the array to a particular value

@Specialization(guards = { "isObject", "!isRubyArray(arguments[3])", "!isUndefinedPlaceholder(arguments[3])" })
public Object setObject(RubyArray array, int start, int length, Object value) {
notDesignedForCompilation();
Expand All @@ -1125,6 +1139,8 @@ public Object setObject(RubyArray array, int start, int length, Object value) {
}
}

// Set a slice of the array to another array

@Specialization(guards = "isIntegerFixnum")
public RubyArray setIntegerFixnumRange(RubyArray array, RubyRange.IntegerFixnumRange range, RubyArray other, UndefinedPlaceholder unused) {
if (range.doesExcludeEnd()) {
Expand Down

0 comments on commit 9da6ed4

Please sign in to comment.