Optimise //count

This commit is contained in:
Starbeamrainbowlabs 2020-09-20 17:53:55 +01:00
parent 358fac7c7c
commit 13278570cb
No known key found for this signature in database
GPG Key ID: 1BE5172E637709C2
2 changed files with 5 additions and 9 deletions

@ -9,6 +9,7 @@ It's about time I started a changelog! This will serve from now on as the master
- Add `//forest` command for quickly generating forests - Add `//forest` command for quickly generating forests
- Fix some minor bugs and edge cases - Fix some minor bugs and edge cases
- `//subdivide`: Print status update when completing the last chunk - `//subdivide`: Print status update when completing the last chunk
- `//count`: Optimise by removing nested `for` loops
## v1.8: The Quality of Life Update (17th July 2020) ## v1.8: The Quality of Life Update (17th July 2020)

@ -16,16 +16,11 @@ function worldeditadditions.count(pos1, pos2)
-- z y x is the preferred loop order (because CPU cache I'd guess, since then we're iterating linearly through the data array) -- z y x is the preferred loop order (because CPU cache I'd guess, since then we're iterating linearly through the data array)
local counts = {} local counts = {}
for z = pos2.z, pos1.z, -1 do for i in area:iterp(pos1, pos2) do
for y = pos2.y, pos1.y, -1 do if not counts[data[i]] then
for x = pos2.x, pos1.x, -1 do counts[data[i]] = 0
local next = data[area:index(x, y, z)]
if not counts[next] then
counts[next] = 0
end
counts[next] = counts[next] + 1
end
end end
counts[data[i]] = counts[data[i]] + 1
end end
local total = worldedit.volume(pos1, pos2) local total = worldedit.volume(pos1, pos2)