Skip to content

Commit

Permalink
small performance optimization by removing unnecessary allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
ImplementsLegend committed Nov 20, 2024
1 parent d13a941 commit c689874
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

Expand All @@ -15,8 +17,24 @@
@Mixin(PartialBlockProperties.class)
public class MixinPartBlockProperties {

private static final HashMap ANTIALLOCATION = new HashMap();

@Redirect(method = "empty", at = @At(value = "NEW", target = "()Ljava/util/HashMap;"), remap = false)
private static HashMap useLinkedHashMap(){
return ANTIALLOCATION;
}
@Redirect(method = "of(Lnet/minecraft/world/level/block/state/BlockState;)Liskallia/vault/core/world/data/tile/PartialBlockProperties;", at = @At(value = "NEW", target = "()Ljava/util/HashMap;"), remap = false)
private static HashMap useLinkedHashMap2(){
return ANTIALLOCATION;
}


@ModifyVariable(method = "<init>", at = @At(value = "HEAD"), argsOnly = true)
private static Map useLinkedHashMap(Map values){
return (values instanceof LinkedHashMap<?,?>)?values:new LinkedHashMap<String,String>(values);
}
@ModifyVariable(method = "of(Lnet/minecraft/world/level/block/state/BlockState;)Liskallia/vault/core/world/data/tile/PartialBlockProperties;", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;getProperties()Ljava/util/Collection;"), argsOnly = false)
private static Map useLinkedHashMap2(Map values){
return new LinkedHashMap<String,String>(values);
}
}

0 comments on commit c689874

Please sign in to comment.