Optimized EditSession.countBlocks.

Also fixed the questionable semantics for that anonymous class' "contains" method.
Dieser Commit ist enthalten in:
TomyLobo 2013-06-23 22:09:50 +02:00
Ursprung 28047894c4
Commit eacd147694

Datei anzeigen

@ -19,6 +19,7 @@
package com.sk89q.worldedit;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
@ -534,6 +535,18 @@ public class EditSession {
return countBlocks(region, passOn);
}
private static boolean containsFuzzy(Collection<BaseBlock> collection, Object o) {
// allow -1 data in the searchBlocks to match any type
for (BaseBlock b : collection) {
if (o instanceof BaseBlock) {
if (b.equalsFuzzy((BaseBlock) o)) {
return true;
}
}
}
return false;
}
/**
* Count the number of blocks of a list of types in a region.
*
@ -544,22 +557,6 @@ public class EditSession {
public int countBlocks(Region region, Set<BaseBlock> searchBlocks) {
int count = 0;
// allow -1 data in the searchBlocks to match any type
Set<BaseBlock> newSet = new HashSet<BaseBlock>() {
@Override
public boolean contains(Object o) {
for (BaseBlock b : this.toArray(new BaseBlock[this.size()])) {
if (o instanceof BaseBlock) {
if (b.equalsFuzzy((BaseBlock) o)) {
return true;
}
}
}
return false;
}
};
newSet.addAll(searchBlocks);
if (region instanceof CuboidRegion) {
// Doing this for speed
Vector min = region.getMinimumPoint();
@ -578,7 +575,7 @@ public class EditSession {
Vector pt = new Vector(x, y, z);
BaseBlock compare = new BaseBlock(getBlockType(pt), getBlockData(pt));
if (newSet.contains(compare)) {
if (containsFuzzy(searchBlocks, compare)) {
++count;
}
}
@ -587,7 +584,7 @@ public class EditSession {
} else {
for (Vector pt : region) {
BaseBlock compare = new BaseBlock(getBlockType(pt), getBlockData(pt));
if (newSet.contains(compare)) {
if (containsFuzzy(searchBlocks, compare)) {
++count;
}
}