Skip to content

Commit cd2328e

Browse files
committed
Better comments and variable names
1 parent 07bb16e commit cd2328e

File tree

1 file changed

+10
-11
lines changed
  • wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command

1 file changed

+10
-11
lines changed

wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
Skipping builds for arm32 (toolchain is marked optional)
2+
Skipping builds for arm64 (toolchain is marked optional)
3+
Skipping builds for roboRio (toolchain is marked optional)
14
// Copyright (c) FIRST and other WPILib contributors.
25
// Open Source Software; you can modify and/or share it under the terms of
36
// the WPILib BSD license file in the root directory of this project.
@@ -15,7 +18,6 @@
1518
import java.util.Collection;
1619
import java.util.HashSet;
1720
import java.util.Set;
18-
import java.util.concurrent.atomic.AtomicInteger;
1921
import java.util.function.BooleanSupplier;
2022

2123
/**
@@ -406,24 +408,21 @@ public RepeatCommand repeatedly() {
406408
* Decorates this command to run repeatedly, restarting until the command runs for the given times
407409
* amount. The decorated command can still be canceled.
408410
*
409-
* <p>This is just syntactic sugar for {@code this.finallyDo(() ->
410-
* counter[0]++).repeatedly().until(() -> counter[0] >= times)} which just means: runs the
411-
* command, then increments the counter, repeatedly until the counter saturates.
412-
*
413411
* <p>Note: This decorator works by adding this command to a composition. The command the
414412
* decorator was called on cannot be scheduled independently or be added to a different
415413
* composition (namely, decorators), unless it is manually cleared from the list of composed
416414
* commands with {@link CommandScheduler#removeComposedCommand(Command)}. The command composition
417415
* returned from this method can be further decorated without issue.
418416
*
419-
* @param times the count of times to run the command (inclusively).
417+
* @param repetitions the count of times to run the command.
420418
* @return the decorated command
421419
*/
422-
public ParallelRaceGroup repeatedly(int times) {
423-
AtomicInteger counter = new AtomicInteger(0);
424-
return this.finallyDo(counter::getAndIncrement)
425-
.repeatedly()
426-
.until(() -> counter.get() >= times);
420+
public ParallelRaceGroup repeatedly(int repetitions) {
421+
// use an array so that it stays in the heap instead of stack.
422+
// We use an array with a size of 1 instead of `AtomicInteger` because of the performance
423+
// overhead
424+
int[] counter = new int[1];
425+
return this.finallyDo(() -> counter[0]++).repeatedly().until(() -> counter[0] >= repetitions);
427426
}
428427

429428
/**

0 commit comments

Comments
 (0)