Optimize clear()

This commit is contained in:
embeddedt 2023-04-28 21:33:57 -04:00
parent 433db3409a
commit c09c4ccf68
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
2 changed files with 8 additions and 10 deletions

View File

@ -98,7 +98,6 @@ public class ForgeRegistryMixin<V extends IForgeRegistryEntry<V>> {
this.fastRegistry.optimize(); this.fastRegistry.optimize();
} }
/*
@Redirect(method = "sync", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/BiMap;clear()V")) @Redirect(method = "sync", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/BiMap;clear()V"))
private void clearBiMap(BiMap map) { private void clearBiMap(BiMap map) {
if(map == this.owners) { if(map == this.owners) {
@ -108,6 +107,4 @@ public class ForgeRegistryMixin<V extends IForgeRegistryEntry<V>> {
} else } else
map.clear(); map.clear();
} }
*/
} }

View File

@ -18,14 +18,14 @@ import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class FastForgeRegistry<V extends IForgeRegistryEntry<V>> { public class FastForgeRegistry<V extends IForgeRegistryEntry<V>> {
private BiMap<Integer, V> ids; private final BiMap<Integer, V> ids;
private DataFieldBiMap<ResourceLocation> names; private final DataFieldBiMap<ResourceLocation> names;
private DataFieldBiMap<ResourceKey<V>> keys; private final DataFieldBiMap<ResourceKey<V>> keys;
private DataFieldBiMap<?> owners; private final DataFieldBiMap<?> owners;
private ResourceKey<Registry<V>> registryKey; private final ResourceKey<Registry<V>> registryKey;
private ObjectArrayList<V> valuesById; private final ObjectArrayList<V> valuesById;
private Object2ObjectOpenHashMap<V, RegistryValueData> infoByValue; private final Object2ObjectOpenHashMap<V, RegistryValueData> infoByValue;
private void storeId(V value, int id) { private void storeId(V value, int id) {
RegistryValueData pair = infoByValue.computeIfAbsent(value, k -> new RegistryValueData()); RegistryValueData pair = infoByValue.computeIfAbsent(value, k -> new RegistryValueData());
@ -58,6 +58,7 @@ public class FastForgeRegistry<V extends IForgeRegistryEntry<V>> {
} }
this.names.clearUnsafe(); this.names.clearUnsafe();
this.keys.clearUnsafe(); this.keys.clearUnsafe();
this.owners.clearUnsafe();
} }
public FastForgeRegistry(ResourceKey<Registry<V>> registryKey) { public FastForgeRegistry(ResourceKey<Registry<V>> registryKey) {