Maybe better use addFirst(), for example in CommandProcessor there is a comment 
that order matters (did not check it more closely), so it’s probably best to 
not reverse orders in any place? The Dequeue Javadoc lists addFirst as the 
aproperiate stack#push replacement.

Gruss
Bernd
--
http://bernd.eckenfels.net
________________________________
Von: serviceability-dev <serviceability-dev-r...@openjdk.java.net> im Auftrag 
von Andrey Turbanov <github.com+741251+turban...@openjdk.java.net>
Gesendet: Monday, September 13, 2021 9:29:26 PM
An: client-libs-...@openjdk.java.net <client-libs-...@openjdk.java.net>; 
serviceability-dev@openjdk.java.net <serviceability-dev@openjdk.java.net>
Betreff: Re: RFR: 8273684: Unnecessary Stack usage

On Sun, 29 Aug 2021 21:14:19 GMT, Andrey Turbanov 
<github.com+741251+turban...@openjdk.org> wrote:

> Usage of thread-safe collection Stack is unnecessary. It's recommended to use 
> ArrayDequeue if a thread-safe implementation is not needed.

Yeah. You are right! TIL that order of iteration is different in ArrayDequeu vs 
Stack: Stack.push() adds to the "end of stack" (it just calls Vector.add()), 
while ArrayDeque.push adds "first element"
Luckily for us there was only one place which depend on this. It's small method 
`javax.swing.text.html.HTMLDocument.HTMLReader#getPathTo`. I've changed method 
to use ArrayList instead.

-------------

PR: https://git.openjdk.java.net/jdk/pull/5294

Reply via email to