mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-27 17:43:53 +01:00
Optimise //count
This commit is contained in:
parent
358fac7c7c
commit
13278570cb
@ -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
|
||||
- Fix some minor bugs and edge cases
|
||||
- `//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)
|
||||
|
@ -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)
|
||||
local counts = {}
|
||||
for z = pos2.z, pos1.z, -1 do
|
||||
for y = pos2.y, pos1.y, -1 do
|
||||
for x = pos2.x, pos1.x, -1 do
|
||||
local next = data[area:index(x, y, z)]
|
||||
if not counts[next] then
|
||||
counts[next] = 0
|
||||
end
|
||||
counts[next] = counts[next] + 1
|
||||
end
|
||||
for i in area:iterp(pos1, pos2) do
|
||||
if not counts[data[i]] then
|
||||
counts[data[i]] = 0
|
||||
end
|
||||
counts[data[i]] = counts[data[i]] + 1
|
||||
end
|
||||
|
||||
local total = worldedit.volume(pos1, pos2)
|
||||
|
Loading…
Reference in New Issue
Block a user