-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
- 9.4.12.0
- 9.4.11.0
- 9.4.10.0
- 9.4.9.0
- 9.4.8.0
- 9.4.7.0
- 9.4.6.0
- 9.4.5.0
- 9.4.4.0
- 9.4.3.0
- 9.4.2.0
- 9.4.1.0
- 9.4.0.0
- 9.3.15.0
- 9.3.14.0
- 9.3.13.0
- 9.3.12.0
- 9.3.11.0
- 9.3.10.0
- 9.3.9.0
- 9.3.8.0
- 9.3.7.0
- 9.3.6.0
- 9.3.5.0
- 9.3.4.0
- 9.3.3.0
- 9.3.2.0
- 9.3.1.0
- 9.3.0.0
- 9.2.21.0
- 9.2.20.1
- 9.2.20.0
- 9.2.19.0
- 9.2.18.0
- 9.2.17.0
- 9.2.16.0
- 9.2.15.0
- 9.2.14.0
- 9.2.13.0
- 9.2.12.0
- 9.2.11.1
- 9.2.11.0
- 9.2.10.0
- 9.2.9.0
- 9.2.8.0
- 9.2.7.0
- 9.2.6.0
- 9.2.5.0
- 9.2.4.1
- 9.2.4.0
- 9.2.3.0
- 9.2.2.0
- 9.2.1.0
- 9.2.0.0
- 9.1.17.0
- 9.1.16.0
- 9.1.15.0
- 9.1.14.0
- 9.1.13.0
- 9.1.12.0
- 9.1.11.0
- 9.1.10.0
- 9.1.9.0
- 9.1.8.0
- 9.1.7.0
- 9.1.6.0
- 9.1.5.0
- 9.1.4.0
- 9.1.3.0
- 9.1.2.0
- 9.1.1.0
- 9.1.0.0
- 9.0.5.0
- 9.0.4.0
- 9.0.3.0
- 9.0.1.0
- 9.0.0.0
- 9.0.0.0.rc2
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2084,16 +2084,112 @@ public InjectNode(RubyContext context, SourceSection sourceSection) { | |
dispatch = DispatchHeadNodeFactory.createMethodCall(context, MissingBehavior.CALL_METHOD_MISSING); | ||
} | ||
|
||
@Specialization(guards = "isIntArray(array)") | ||
@Specialization(guards = { "isIntArray(array)", "wasProvided(initial)" }) | ||
public Object injectIntegerFixnum(VirtualFrame frame, RubyArray array, Object initial, RubyProc block) { | ||
return injectIntegerFixnumHelper(frame, array, initial, block, 0); | ||
} | ||
|
||
@Specialization(guards = { "isIntArray(array)", "wasNotProvided(initial)" }) | ||
public Object injectIntegerFixnumNoInitial(VirtualFrame frame, RubyArray array, Object initial, RubyProc block) { | ||
if (getSize(array) > 0) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
nirvdrum
Author
Contributor
|
||
final int[] store = (int[]) getStore(array); | ||
|
||
return injectIntegerFixnumHelper(frame, array, store[0], block, 1); | ||
} | ||
|
||
return nil(); | ||
} | ||
|
||
@Specialization(guards = { "isLongArray(array)", "wasProvided(initial)" }) | ||
public Object injectLongFixnum(VirtualFrame frame, RubyArray array, Object initial, RubyProc block) { | ||
return injectLongFixnumHelper(frame, array, initial, block, 0); | ||
} | ||
|
||
@Specialization(guards = { "isLongArray(array)", "wasNotProvided(initial)" }) | ||
public Object injectLongFixnumNoInitial(VirtualFrame frame, RubyArray array, Object initial, RubyProc block) { | ||
if (getSize(array) > 0) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
final long[] store = (long[]) getStore(array); | ||
|
||
return injectLongFixnumHelper(frame, array, store[0], block, 1); | ||
} | ||
|
||
return nil(); | ||
} | ||
|
||
@Specialization(guards = { "isDoubleArray(array)", "wasProvided(initial)" }) | ||
public Object injectFloat(VirtualFrame frame, RubyArray array, Object initial, RubyProc block) { | ||
return injectFloatHelper(frame, array, initial, block, 0); | ||
} | ||
|
||
@Specialization(guards = { "isDoubleArray(array)", "wasNotProvided(initial)" }) | ||
public Object injectFloatNoInitial(VirtualFrame frame, RubyArray array, Object initial, RubyProc block) { | ||
if (getSize(array) > 0) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
final double[] store = (double[]) getStore(array); | ||
|
||
return injectFloatHelper(frame, array, store[0], block, 1); | ||
} | ||
|
||
return nil(); | ||
} | ||
|
||
@Specialization(guards = { "isObjectArray(array)", "wasProvided(initial)" }) | ||
public Object injectObject(VirtualFrame frame, RubyArray array, Object initial, RubyProc block) { | ||
return injectObjectHelper(frame, array, initial, block, 0); | ||
} | ||
|
||
@Specialization(guards = { "isObjectArray(array)", "wasNotProvided(initial)" }) | ||
public Object injectObjectNoInitial(VirtualFrame frame, RubyArray array, Object initial, RubyProc block) { | ||
if (getSize(array) > 0) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
final Object[] store = (Object[]) getStore(array); | ||
|
||
return injectObjectHelper(frame, array, store[0], block, 1); | ||
} | ||
|
||
return nil(); | ||
} | ||
|
||
@Specialization(guards = { "isNullArray(array)", "wasProvided(initial)" }) | ||
public Object injectNull(VirtualFrame frame, RubyArray array, Object initial, RubyProc block) { | ||
return initial; | ||
} | ||
|
||
@Specialization(guards = { "isNullArray(array)", "wasNotProvided(initial)" }) | ||
public Object injectNullNoInitial(VirtualFrame frame, RubyArray array, Object initial, RubyProc block) { | ||
return nil(); | ||
} | ||
|
||
@Specialization(guards = "isRubySymbol(symbol)") | ||
public Object inject(VirtualFrame frame, RubyArray array, RubyBasicObject symbol, NotProvided block) { | ||
CompilerDirectives.transferToInterpreter(); | ||
|
||
final Object[] store = slowToArray(array); | ||
This comment has been minimized.
Sorry, something went wrong.
chrisseaton
Contributor
|
||
|
||
if (store.length < 2) { | ||
if (store.length == 1) { | ||
return store[0]; | ||
} else { | ||
return getContext().getCoreLibrary().getNilObject(); | ||
} | ||
} | ||
|
||
Object accumulator = dispatch.call(frame, store[0], symbol, null, store[1]); | ||
|
||
for (int n = 2; n < getSize(array); n++) { | ||
accumulator = dispatch.call(frame, accumulator, symbol, null, store[n]); | ||
} | ||
|
||
return accumulator; | ||
} | ||
|
||
private Object injectIntegerFixnumHelper(VirtualFrame frame, RubyArray array, Object initial, RubyProc block, int startIndex) { | ||
int count = 0; | ||
|
||
final int[] store = (int[]) getStore(array); | ||
|
||
Object accumulator = initial; | ||
|
||
try { | ||
for (int n = 0; n < getSize(array); n++) { | ||
for (int n = startIndex; n < getSize(array); n++) { | ||
if (CompilerDirectives.inInterpreter()) { | ||
count++; | ||
} | ||
|
@@ -2109,16 +2205,15 @@ public Object injectIntegerFixnum(VirtualFrame frame, RubyArray array, Object in | |
return accumulator; | ||
} | ||
|
||
@Specialization(guards = "isLongArray(array)") | ||
public Object injectLongFixnum(VirtualFrame frame, RubyArray array, Object initial, RubyProc block) { | ||
private Object injectLongFixnumHelper(VirtualFrame frame, RubyArray array, Object initial, RubyProc block, int startIndex) { | ||
int count = 0; | ||
|
||
final long[] store = (long[]) getStore(array); | ||
|
||
Object accumulator = initial; | ||
|
||
try { | ||
for (int n = 0; n < getSize(array); n++) { | ||
for (int n = startIndex; n < getSize(array); n++) { | ||
if (CompilerDirectives.inInterpreter()) { | ||
count++; | ||
} | ||
|
@@ -2134,16 +2229,15 @@ public Object injectLongFixnum(VirtualFrame frame, RubyArray array, Object initi | |
return accumulator; | ||
} | ||
|
||
@Specialization(guards = "isDoubleArray(array)") | ||
public Object injectFloat(VirtualFrame frame, RubyArray array, Object initial, RubyProc block) { | ||
private Object injectFloatHelper(VirtualFrame frame, RubyArray array, Object initial, RubyProc block, int startIndex) { | ||
int count = 0; | ||
|
||
final double[] store = (double[]) getStore(array); | ||
|
||
Object accumulator = initial; | ||
|
||
try { | ||
for (int n = 0; n < getSize(array); n++) { | ||
for (int n = startIndex; n < getSize(array); n++) { | ||
if (CompilerDirectives.inInterpreter()) { | ||
count++; | ||
} | ||
|
@@ -2159,16 +2253,15 @@ public Object injectFloat(VirtualFrame frame, RubyArray array, Object initial, R | |
return accumulator; | ||
} | ||
|
||
@Specialization(guards = "isObjectArray(array)") | ||
public Object injectObject(VirtualFrame frame, RubyArray array, Object initial, RubyProc block) { | ||
private Object injectObjectHelper(VirtualFrame frame, RubyArray array, Object initial, RubyProc block, int startIndex) { | ||
int count = 0; | ||
|
||
final Object[] store = (Object[]) getStore(array); | ||
|
||
Object accumulator = initial; | ||
|
||
try { | ||
for (int n = 0; n < getSize(array); n++) { | ||
for (int n = startIndex; n < getSize(array); n++) { | ||
if (CompilerDirectives.inInterpreter()) { | ||
count++; | ||
} | ||
|
@@ -2184,34 +2277,6 @@ public Object injectObject(VirtualFrame frame, RubyArray array, Object initial, | |
return accumulator; | ||
} | ||
|
||
@Specialization(guards = "isNullArray(array)") | ||
public Object injectNull(VirtualFrame frame, RubyArray array, Object initial, RubyProc block) { | ||
return initial; | ||
} | ||
|
||
@Specialization(guards = "isRubySymbol(symbol)") | ||
public Object inject(VirtualFrame frame, RubyArray array, RubyBasicObject symbol, NotProvided block) { | ||
CompilerDirectives.transferToInterpreter(); | ||
|
||
final Object[] store = slowToArray(array); | ||
|
||
if (store.length < 2) { | ||
if (store.length == 1) { | ||
return store[0]; | ||
} else { | ||
return getContext().getCoreLibrary().getNilObject(); | ||
} | ||
} | ||
|
||
Object accumulator = dispatch.call(frame, store[0], symbol, null, store[1]); | ||
|
||
for (int n = 2; n < getSize(array); n++) { | ||
accumulator = dispatch.call(frame, accumulator, symbol, null, store[n]); | ||
} | ||
|
||
return accumulator; | ||
} | ||
|
||
} | ||
|
||
@CoreMethod(names = "insert", required = 1, raiseIfFrozenSelf = true, argumentsAsArray = true) | ||
|
1 comment
on commit 2ccf01e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chrisseaton Could you please spot check this for me and make sure I didn't do anything that would hurt performance?
I would make this a guard using
isEmptyArray
.