|
| 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) |
1 | 4 | // Copyright (c) FIRST and other WPILib contributors.
|
2 | 5 | // Open Source Software; you can modify and/or share it under the terms of
|
3 | 6 | // the WPILib BSD license file in the root directory of this project.
|
|
15 | 18 | import java.util.Collection;
|
16 | 19 | import java.util.HashSet;
|
17 | 20 | import java.util.Set;
|
18 |
| -import java.util.concurrent.atomic.AtomicInteger; |
19 | 21 | import java.util.function.BooleanSupplier;
|
20 | 22 |
|
21 | 23 | /**
|
@@ -406,24 +408,21 @@ public RepeatCommand repeatedly() {
|
406 | 408 | * Decorates this command to run repeatedly, restarting until the command runs for the given times
|
407 | 409 | * amount. The decorated command can still be canceled.
|
408 | 410 | *
|
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 |
| - * |
413 | 411 | * <p>Note: This decorator works by adding this command to a composition. The command the
|
414 | 412 | * decorator was called on cannot be scheduled independently or be added to a different
|
415 | 413 | * composition (namely, decorators), unless it is manually cleared from the list of composed
|
416 | 414 | * commands with {@link CommandScheduler#removeComposedCommand(Command)}. The command composition
|
417 | 415 | * returned from this method can be further decorated without issue.
|
418 | 416 | *
|
419 |
| - * @param times the count of times to run the command (inclusively). |
| 417 | + * @param repetitions the count of times to run the command. |
420 | 418 | * @return the decorated command
|
421 | 419 | */
|
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); |
427 | 426 | }
|
428 | 427 |
|
429 | 428 | /**
|
|
0 commit comments