-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix builder.State.write internalization
Using generic Map interface instead of SimpleLookupTable showed up that State.write(DataOutputStream) did use Arrays (char[] / char[][]) as key in internedRootNames, internedQualifiedNames, internedSimpleNames. Arrays however do have equals() contract based on identity. Therefore the code did not deduplicate anything as intended. It normally only did not matter as most char arrays in jdt are already weakly deduplicated.
- Loading branch information
Showing
3 changed files
with
159 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...pse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/util/CharCharArray.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 jkubitz and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* jkubitz - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.internal.compiler.util; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* Wrapper around char[][] that can be used as a key in a Map or Set. | ||
*/ | ||
public final record CharCharArray(char[][] key) implements Comparable<CharCharArray> { | ||
|
||
@Override | ||
public int compareTo(CharCharArray other) { | ||
// just any technical sort order for Comparable interface used in HashMap https://openjdk.org/jeps/180 | ||
int d = this.key.length - other.key.length; | ||
if (d != 0) { | ||
return d; | ||
} | ||
int length = this.key.length; | ||
for (int i = 0; i < length; i++) { | ||
int c = Arrays.compare(this.key[i], other.key[i]); | ||
if (c != 0) { | ||
return c; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
public char[][] getKey() { | ||
return this.key; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj instanceof CharCharArray other) { | ||
return Arrays.deepEquals(this.key, other.key); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Arrays.deepHashCode(this.key); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return Arrays.deepToString(this.key); | ||
} | ||
} |
Oops, something went wrong.