> From: "임민수" <godmlz...@naver.com> > To: "core-libs-dev" <core-libs-dev@openjdk.org> > Sent: Friday, May 9, 2025 10:33:30 AM > Subject: Unnecessary logic is added to removeFirst and removeLast of > ArrayList.
> Hi. > In removeFirst, if size is not 0, the logic is the same as the remove logic. > removeLast also has the same logic as remove when size is not exceeded. > I want to fix this. > thank you. Duplicating the logic is bad in some cases and not that bad in other cases. Here ArrayList is one of the most used class in Java (with String and HashMap), it is heavily optimized (to the point where the generated assembly code by the JITs is checked by humans), so duplicating the logic is not a bad idea, >From a documentation POV, you do not have to jump through many methods if you >want to see the implementation and in terms of performance, you want the >inlining to be done by hand because the methods of ArrayList are usually deep >in the call graph, so you may reach the inlining threshold right inside >removeFirst(). In general, you do not optimize applications and libraries the same way. Usually, you do not optimize application code that often but for a library, if a lot of people are using it, it may worth to spend time to optimize for the benefit of everybody. regards, Rémi