< prev index next >
src/java.base/share/classes/java/lang/invoke/MethodHandles.java
Print this page
*** 4320,4334 ****
* <p>
* @implSpec The implementation of this method is equivalent to:
* <blockquote><pre>{@code
* MethodHandle countedLoop(MethodHandle start, MethodHandle end, MethodHandle init, MethodHandle body) {
* MethodHandle returnVar = dropArguments(identity(init.type().returnType()), 0, int.class, int.class);
! * // assume MH_increment and MH_lessThan are handles to x+1 and x<y of type int
* MethodHandle[]
* indexVar = {start, MH_increment}, // i = start; i = i+1
* loopLimit = {end, null, MH_lessThan, returnVar }, // i<end
! * bodyClause = {init, dropArguments(body, 1, int.class)}; // v = body(i, v);
* return loop(indexVar, loopLimit, bodyClause);
* }
* }</pre></blockquote>
*
* @param start a handle to return the start value of the loop counter.
--- 4320,4336 ----
* <p>
* @implSpec The implementation of this method is equivalent to:
* <blockquote><pre>{@code
* MethodHandle countedLoop(MethodHandle start, MethodHandle end, MethodHandle init, MethodHandle body) {
* MethodHandle returnVar = dropArguments(identity(init.type().returnType()), 0, int.class, int.class);
! * // assume MH_increment and MH_lessThan are handles to x+1 and x<y of type int,
! * // assume MH_decrement is a handle to x-1 of type int
* MethodHandle[]
* indexVar = {start, MH_increment}, // i = start; i = i+1
* loopLimit = {end, null, MH_lessThan, returnVar }, // i<end
! * bodyClause = {init,
! * filterArgument(dropArguments(body, 1, int.class), 0, MH_decrement}; // v = body(i-1, v)
* return loop(indexVar, loopLimit, bodyClause);
* }
* }</pre></blockquote>
*
* @param start a handle to return the start value of the loop counter.
*** 4349,4359 ****
public static MethodHandle countedLoop(MethodHandle start, MethodHandle end, MethodHandle init, MethodHandle body) {
MethodHandle returnVar = dropArguments(init == null ? zeroHandle(void.class) : identity(init.type().returnType()),
0, int.class, int.class);
MethodHandle[] indexVar = {start, MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_countedLoopStep)};
MethodHandle[] loopLimit = {end, null, MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_countedLoopPred), returnVar};
! MethodHandle[] bodyClause = {init, dropArguments(body, 1, int.class)};
return loop(indexVar, loopLimit, bodyClause);
}
/**
* Constructs a loop that ranges over the elements produced by an {@code Iterator<T>}.
--- 4351,4363 ----
public static MethodHandle countedLoop(MethodHandle start, MethodHandle end, MethodHandle init, MethodHandle body) {
MethodHandle returnVar = dropArguments(init == null ? zeroHandle(void.class) : identity(init.type().returnType()),
0, int.class, int.class);
MethodHandle[] indexVar = {start, MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_countedLoopStep)};
MethodHandle[] loopLimit = {end, null, MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_countedLoopPred), returnVar};
! MethodHandle[] bodyClause = {init,
! filterArgument(dropArguments(body, 1, int.class), 0,
! MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_decrementCounter))};
return loop(indexVar, loopLimit, bodyClause);
}
/**
* Constructs a loop that ranges over the elements produced by an {@code Iterator<T>}.
< prev index next >