There's no need to duplicate everything when copying the intersection masks, as the Set and array should be the same. (#680)

* There's no need to duplicate everything when copying the intersection masks, as the Set and array should be the same.

* do the same for Union mask
This commit is contained in:
dordsor21 2020-10-04 18:49:45 +01:00 committed by GitHub
parent fc606ff5ff
commit b06d943f7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 15 deletions

View File

@ -61,12 +61,6 @@ public class MaskIntersection extends AbstractMask {
formArray();
}
protected MaskIntersection(Set<Mask> masks, Mask[] masksArray, boolean defaultReturn) {
this.masks = masks;
this.masksArray = masksArray;
this.defaultReturn = defaultReturn;
}
public static Mask of(Mask... masks) {
Set<Mask> set = new LinkedHashSet<>();
for (Mask mask : masks) {
@ -260,8 +254,7 @@ public class MaskIntersection extends AbstractMask {
@Override
public Mask copy(){
Set<Mask> masks = this.masks.stream().map(Mask::copy).collect(Collectors.toSet());
Mask[] maskArray = (Mask[]) Arrays.stream(this.masksArray).map(Mask::copy).toArray();
return new MaskIntersection(masks, maskArray, this.defaultReturn);
return new MaskIntersection(masks);
}
}

View File

@ -22,7 +22,6 @@ package com.sk89q.worldedit.function.mask;
import com.sk89q.worldedit.math.BlockVector3;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
@ -57,10 +56,6 @@ public class MaskUnion extends MaskIntersection {
super(mask);
}
private MaskUnion(Set<Mask> masks, Mask[] maskArray, boolean defaultReturn) {
super(masks, maskArray, defaultReturn);
}
public static Mask of(Mask... masks) {
Set<Mask> set = new LinkedHashSet<>();
for (Mask mask : masks) {
@ -121,7 +116,6 @@ public class MaskUnion extends MaskIntersection {
@Override
public Mask copy() {
Set<Mask> masksCopy = masks.stream().map(Mask::copy).collect(Collectors.toSet());
Mask[] maskArray = (Mask[]) Arrays.stream(masksArray).map(Mask::copy).toArray();
return new MaskUnion(masksCopy, maskArray, defaultReturn);
return new MaskUnion(masksCopy);
}
}