Skip to content

Commit 14f1552

Browse files
committed
Use Guava immutable list to avoid extra internal copying
1 parent 61c8cfd commit 14f1552

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

forge/src/main/java/org/embeddedt/modernfix/forge/dynresources/ModelLocationBuilder.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.embeddedt.modernfix.forge.dynresources;
22

3+
import com.google.common.collect.ImmutableList;
34
import com.google.common.collect.Lists;
45
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
56
import net.minecraft.client.resources.model.ModelResourceLocation;
@@ -17,11 +18,11 @@ public class ModelLocationBuilder {
1718
private final Map<Property<?>, PropertyData> propertyToOptionStrings = new Object2ObjectOpenHashMap<>();
1819
private final StringBuilder builder = new StringBuilder();
1920

20-
private record PropertyData(List<String> nameValuePairs, int maxPairLength) {}
21+
private record PropertyData(ImmutableList<String> nameValuePairs, int maxPairLength) {}
2122

2223
public void generateForBlock(Set<ResourceLocation> destinationSet, Block block, ResourceLocation baseLocation) {
2324
var props = block.getStateDefinition().getProperties();
24-
List<List<String>> optionsList = new ArrayList<>(props.size());
25+
List<ImmutableList<String>> optionsList = new ArrayList<>(props.size());
2526
int requiredBuilderSize = Math.max(0, props.size() - 1); // commas
2627
for (var prop : props) {
2728
var data = propertyToOptionStrings.computeIfAbsent(prop, ModelLocationBuilder::computePropertyOptions);
@@ -47,14 +48,14 @@ public void generateForBlock(Set<ResourceLocation> destinationSet, Block block,
4748
}
4849

4950
private static PropertyData computePropertyOptions(Property<?> prop) {
50-
List<String> valuesList = new ArrayList<>(prop.getPossibleValues().size());
51+
ImmutableList.Builder<String> valuesList = ImmutableList.builderWithExpectedSize(prop.getPossibleValues().size());
5152
int maxLength = 0;
5253
for (var val : prop.getPossibleValues()) {
5354
String pair = prop.getName() + "=" + getValueName(prop, val);
5455
valuesList.add(pair.toLowerCase(Locale.ROOT));
5556
maxLength = Math.max(pair.length(), maxLength);
5657
}
57-
return new PropertyData(List.copyOf(valuesList), maxLength);
58+
return new PropertyData(valuesList.build(), maxLength);
5859
}
5960

6061
private static <T extends Comparable<T>> String getValueName(Property<T> property, Comparable<?> value) {

0 commit comments

Comments
 (0)