On Tue, 21 Feb 2023 20:39:53 GMT, Tagir F. Valeev <[email protected]> wrote:
>> For cleanup and dogfooding the new method, it would be nice to use
>> Math.clamp where possible in java.base. See PR #12428.
>>
>> As Math.clamp performs an additional check that min is not greater than max,
>> I conservatively replaced only those occurrences where I can see that this
>> invariant is always held. There are more occurrences, where clamp can be
>> potentially used but it's unclear whether min <= max is always true.
>
> Tagir F. Valeev has updated the pull request incrementally with one
> additional commit since the last revision:
>
> Update copyright year
I only saw this PR after it has been integrated. A code location that
immediately came to mind but was missing in the change is this
java/util/concurrent/SubmissionPublisher.java:1273:
public final void request(long n) {
if (n > 0L) {
for (;;) {
long p = demand, d = p + n; // saturate
if (casDemand(p, d < p ? Long.MAX_VALUE : d))
break;
}
startOnSignal(RUN | ACTIVE | REQS);
}
else
onError(new IllegalArgumentException(
"non-positive subscription request"));
}
Seems like a poster child for the new Math.clamp functionality.
-------------
PR: https://git.openjdk.org/jdk/pull/12633