|
104 | 104 | import com.oracle.truffle.api.dsl.NodeChild;
|
105 | 105 | import com.oracle.truffle.api.dsl.ReportPolymorphism;
|
106 | 106 | import com.oracle.truffle.api.dsl.Specialization;
|
| 107 | +import com.oracle.truffle.api.dsl.Cached.Shared; |
107 | 108 | import com.oracle.truffle.api.frame.VirtualFrame;
|
108 | 109 | import com.oracle.truffle.api.library.CachedLibrary;
|
109 | 110 | import com.oracle.truffle.api.nodes.DirectCallNode;
|
@@ -280,26 +281,27 @@ protected Object index(RubyArray array, int index, NotProvided length,
|
280 | 281 |
|
281 | 282 | @Specialization
|
282 | 283 | protected Object indexRange(RubyArray array, RubyObjectRange range, NotProvided length,
|
283 |
| - @Cached NormalizedStartLengthNode startLengthNode, |
284 |
| - @Cached ReadSliceNormalizedNode readSlice) { |
285 |
| - final int[] startLength = startLengthNode.execute(range, array.size); |
286 |
| - final int len = Math.max(startLength[1], 0); // negative range ending maps to zero length |
287 |
| - return readSlice.executeReadSlice(array, startLength[0], len); |
| 284 | + @Cached @Shared("starting") NormalizedStartLengthNode startLengthNode, |
| 285 | + @Cached @Shared("ending") ReadSliceNormalizedNode readSlice) { |
| 286 | + return readRange(array, range, startLengthNode, readSlice); |
288 | 287 | }
|
289 | 288 |
|
290 | 289 | @Specialization
|
291 | 290 | protected Object indexIntRange(RubyArray array, RubyIntRange range, NotProvided length,
|
292 |
| - @Cached NormalizedStartLengthNode startLengthNode, |
293 |
| - @Cached ReadSliceNormalizedNode readSlice) { |
294 |
| - final int[] startLength = startLengthNode.execute(range, array.size); |
295 |
| - final int len = Math.max(startLength[1], 0); // negative range ending maps to zero length |
296 |
| - return readSlice.executeReadSlice(array, startLength[0], len); |
| 291 | + @Cached @Shared("starting") NormalizedStartLengthNode startLengthNode, |
| 292 | + @Cached @Shared("ending") ReadSliceNormalizedNode readSlice) { |
| 293 | + return readRange(array, range, startLengthNode, readSlice); |
297 | 294 | }
|
298 | 295 |
|
299 | 296 | @Specialization
|
300 | 297 | protected Object indexLongRange(RubyArray array, RubyLongRange range, NotProvided length,
|
301 |
| - @Cached NormalizedStartLengthNode startLengthNode, |
302 |
| - @Cached ReadSliceNormalizedNode readSlice) { |
| 298 | + @Cached @Shared("starting") NormalizedStartLengthNode startLengthNode, |
| 299 | + @Cached @Shared("ending") ReadSliceNormalizedNode readSlice) { |
| 300 | + return readRange(array, range, startLengthNode, readSlice); |
| 301 | + } |
| 302 | + |
| 303 | + private Object readRange(RubyArray array, Object range, NormalizedStartLengthNode startLengthNode, |
| 304 | + ReadSliceNormalizedNode readSlice) { |
303 | 305 | final int[] startLength = startLengthNode.execute(range, array.size);
|
304 | 306 | final int len = Math.max(startLength[1], 0); // negative range ending maps to zero length
|
305 | 307 | return readSlice.executeReadSlice(array, startLength[0], len);
|
@@ -382,42 +384,27 @@ protected Object set(RubyArray array, int index, Object value, NotProvided unuse
|
382 | 384 |
|
383 | 385 | @Specialization
|
384 | 386 | protected Object setRange(RubyArray array, RubyObjectRange range, Object value, NotProvided unused,
|
385 |
| - @Cached NormalizedStartLengthNode normalizedStartLength, |
386 |
| - @Cached BranchProfile negativeStart) { |
387 |
| - final int[] startLength = normalizedStartLength.execute(range, array.size); |
388 |
| - final int start = startLength[0]; |
389 |
| - if (start < 0) { |
390 |
| - negativeStart.enter(); |
391 |
| - throw new RaiseException( |
392 |
| - getContext(), |
393 |
| - coreExceptions().rangeError(Utils.concat("index ", start, " out of bounds"), this)); |
394 |
| - } |
395 |
| - final int length = Math.max(startLength[1], 0); // negative range ending maps to zero length |
396 |
| - return executeIntIndices(array, start, length, value); |
| 387 | + @Cached @Shared("startLength") NormalizedStartLengthNode normalizedStartLength, |
| 388 | + @Cached @Shared("nagativeStart") BranchProfile negativeStart) { |
| 389 | + return setRangeInternal(array, range, value, normalizedStartLength, negativeStart); |
397 | 390 | }
|
398 | 391 |
|
399 |
| - |
400 | 392 | @Specialization
|
401 | 393 | protected Object setIngRange(RubyArray array, RubyIntRange range, Object value, NotProvided unused,
|
402 |
| - @Cached NormalizedStartLengthNode normalizedStartLength, |
403 |
| - @Cached BranchProfile negativeStart) { |
404 |
| - final int[] startLength = normalizedStartLength.execute(range, array.size); |
405 |
| - final int start = startLength[0]; |
406 |
| - if (start < 0) { |
407 |
| - negativeStart.enter(); |
408 |
| - throw new RaiseException( |
409 |
| - getContext(), |
410 |
| - coreExceptions().rangeError(Utils.concat("index ", start, " out of bounds"), this)); |
411 |
| - } |
412 |
| - final int length = Math.max(startLength[1], 0); // negative range ending maps to zero length |
413 |
| - return executeIntIndices(array, start, length, value); |
| 394 | + @Cached @Shared("startLength") NormalizedStartLengthNode normalizedStartLength, |
| 395 | + @Cached @Shared("nagativeStart") BranchProfile negativeStart) { |
| 396 | + return setRangeInternal(array, range, value, normalizedStartLength, negativeStart); |
414 | 397 | }
|
415 | 398 |
|
416 |
| - |
417 | 399 | @Specialization
|
418 | 400 | protected Object setLongRange(RubyArray array, RubyLongRange range, Object value, NotProvided unused,
|
419 |
| - @Cached NormalizedStartLengthNode normalizedStartLength, |
420 |
| - @Cached BranchProfile negativeStart) { |
| 401 | + @Cached @Shared("startLength") NormalizedStartLengthNode normalizedStartLength, |
| 402 | + @Cached @Shared("nagativeStart") BranchProfile negativeStart) { |
| 403 | + return setRangeInternal(array, range, value, normalizedStartLength, negativeStart); |
| 404 | + } |
| 405 | + |
| 406 | + private Object setRangeInternal(RubyArray array, Object range, Object value, |
| 407 | + NormalizedStartLengthNode normalizedStartLength, BranchProfile negativeStart) { |
421 | 408 | final int[] startLength = normalizedStartLength.execute(range, array.size);
|
422 | 409 | final int start = startLength[0];
|
423 | 410 | if (start < 0) {
|
|
0 commit comments