Skip to content

Commit 81d79e3

Browse files
cushonJavac Team
authored andcommitted
Return a char from formatReleaseVersion
Currently it always returns a `String` of length 1. This matches code in the JDK that is going to require updates for JDK 36, but I'm going to worry about that later. The motivation is that this is the only place that `String#contains` is used in a context where string views could be used instead. PiperOrigin-RevId: 690664119
1 parent fdeba1e commit 81d79e3

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

java/com/google/turbine/binder/CtSymClassBinder.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.google.turbine.binder;
1818

19-
import static com.google.common.base.Ascii.toUpperCase;
2019
import static com.google.common.base.StandardSystemProperty.JAVA_HOME;
2120
import static java.util.Objects.requireNonNull;
2221

@@ -70,10 +69,7 @@ public final class CtSymClassBinder {
7069
return map.get(sym);
7170
}
7271
};
73-
// ct.sym contains directories whose names are the concatentation of a list of target versions
74-
// formatted as a single character 0-9 or A-Z (e.g. 789A) and which contain interface class
75-
// files with a .sig extension.
76-
String releaseString = formatReleaseVersion(version);
72+
char releaseChar = formatReleaseVersion(version);
7773
for (Zip.Entry ze : new Zip.ZipIterable(ctSym)) {
7874
String name = ze.name();
7975
if (!name.endsWith(".sig")) {
@@ -84,7 +80,7 @@ public final class CtSymClassBinder {
8480
continue;
8581
}
8682
// check if the directory matches the desired release
87-
if (!ze.name().substring(0, idx).contains(releaseString)) {
83+
if (ze.name().substring(0, idx).indexOf(releaseChar) == -1) {
8884
continue;
8985
}
9086
// JDK >= 12 includes the module name as a prefix
@@ -138,12 +134,21 @@ public byte[] get() {
138134
});
139135
}
140136

137+
// ct.sym contains directories whose names are the concatenation of a list of target versions
138+
// formatted as a single character 0-9 or A-Z (e.g. 789A) and which contain interface class
139+
// files with a .sig extension.
140+
// This was updated to use 36 as a radix in https://bugs.openjdk.org/browse/JDK-8245544,
141+
// it's not clear what the plan is for JDK 36.
141142
@VisibleForTesting
142-
static String formatReleaseVersion(int n) {
143+
static char formatReleaseVersion(int n) {
143144
if (n <= 4 || n >= 36) {
144145
throw new IllegalArgumentException("invalid release version: " + n);
145146
}
146-
return toUpperCase(Integer.toString(n, 36));
147+
if (n < 10) {
148+
return (char) ('0' + n);
149+
} else {
150+
return (char) ('A' + n - 10);
151+
}
147152
}
148153

149154
private CtSymClassBinder() {}

javatests/com/google/turbine/binder/CtSymClassBinderTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ public class CtSymClassBinderTest {
3131
public void formatReleaseVersion() {
3232
ImmutableList.of(5, 6, 7, 8, 9)
3333
.forEach(
34-
x -> assertThat(CtSymClassBinder.formatReleaseVersion(x)).isEqualTo(String.valueOf(x)));
34+
x ->
35+
assertThat(Character.toString(CtSymClassBinder.formatReleaseVersion(x)))
36+
.isEqualTo(String.valueOf(x)));
3537
ImmutableMap.of(
36-
10, "A",
37-
11, "B",
38-
12, "C",
39-
35, "Z")
38+
10, 'A',
39+
11, 'B',
40+
12, 'C',
41+
35, 'Z')
4042
.forEach((k, v) -> assertThat(CtSymClassBinder.formatReleaseVersion(k)).isEqualTo(v));
4143
ImmutableList.of(4, 36)
4244
.forEach(

0 commit comments

Comments
 (0)