diff --git a/core/src/main/java/com/sk89q/worldedit/EditSession.java b/core/src/main/java/com/sk89q/worldedit/EditSession.java index 79328327..c27782a4 100644 --- a/core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -2523,8 +2523,7 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting * @return the results */ public List> getBlockDistribution(final Region region) { - final List> distribution = new ArrayList>(); - final Map> map = new HashMap>(); + int[] counter = new int[256]; if (region instanceof CuboidRegion) { // Doing this for speed @@ -2542,28 +2541,23 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting for (int y = minY; y <= maxY; ++y) { for (int z = minZ; z <= maxZ; ++z) { int id = FaweCache.getId(queue.getCombinedId4Data(x, y, z)); - if (map.containsKey(id)) { - map.get(id).increment(); - } else { - final Countable c = new Countable(id, 1); - map.put(id, c); - distribution.add(c); - } + counter[id]++; } } } } else { for (final Vector pt : region) { final int id = this.getBlockType(pt); - if (map.containsKey(id)) { - map.get(id).increment(); - } else { - final Countable c = new Countable(id, 1); - map.put(id, c); - } + counter[id]++; + } + } + List> distribution = new ArrayList<>(); + for (int i = 0; i < counter.length; i++) { + int count = counter[i]; + if (count != 0) { + distribution.add(new Countable(i, count)); } } - Collections.sort(distribution); // Collections.reverse(distribution); @@ -2577,8 +2571,7 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting * @return the results */ public List> getBlockDistributionWithData(final Region region) { - final List> distribution = new ArrayList>(); - final Map> map = new HashMap>(); + int[] counter = new int[Character.MAX_VALUE + 1]; if (region instanceof CuboidRegion) { // Doing this for speed @@ -2596,29 +2589,23 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting for (int y = minY; y <= maxY; ++y) { for (int z = minZ; z <= maxZ; ++z) { final BaseBlock blk = getLazyBlock(x, y, z); - if (map.containsKey(blk)) { - map.get(blk).increment(); - } else { - final Countable c = new Countable(blk, 1); - map.put(blk, c); - distribution.add(c); - } + counter[FaweCache.getCombined(blk)]++; } } } } else { for (final Vector pt : region) { final BaseBlock blk = FaweCache.getBlock(this.getBlockType(pt), this.getBlockData(pt)); - - if (map.containsKey(blk)) { - map.get(blk).increment(); - } else { - final Countable c = new Countable(blk, 1); - map.put(blk, c); - } + counter[FaweCache.getCombined(blk)]++; + } + } + List> distribution = new ArrayList<>(); + for (int i = 0; i < counter.length; i++) { + int count = counter[i]; + if (count != 0) { + distribution.add(new Countable(FaweCache.CACHE_BLOCK[i], count)); } } - Collections.sort(distribution); // Collections.reverse(distribution);