RFR: 8313865: Always true condition in sun.nio.cs.CharsetMapping#readINDEXC2B

Aleksey Shipilev shade at openjdk.org
Wed Sep 13 07:25:51 UTC 2023


On Mon, 11 Sep 2023 22:21:03 GMT, Naoto Sato <naoto at openjdk.org> wrote:

> Simple clean-up for removing an unnecessary condition.

src/java.base/share/classes/sun/nio/cs/CharsetMapping.java line 242:

> 240:         char[] map = readCharArray();
> 241:         for (int i = map.length - 1; i >= 0; i--) {
> 242:             if (c2b == null) {

Post-review comment:

I don't quite understand this code. `c2b` is loop-invariant, right? So, what this does is checking for `c2b != null`, and if so, instantiates the `c2b` array with `new char[map[map.length - 1] + 256]`. This does not even require a loop, as written right now.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/15672#discussion_r1324084796


More information about the nio-dev mailing list