diff options
| author | Daniel Schadt <kingdread@gmx.de> | 2025-12-14 21:52:39 +0100 |
|---|---|---|
| committer | Daniel Schadt <kingdread@gmx.de> | 2025-12-14 21:52:39 +0100 |
| commit | a3b378fd66342ecf9a44f814acf1b18a49a05c42 (patch) | |
| tree | 596738b3e2edb4eb136c223fc82756189f08b3cb | |
| parent | 79c600652df850bc8b9f90185d2dc4b39c9599cb (diff) | |
| download | hittekaart-a3b378fd66342ecf9a44f814acf1b18a49a05c42.tar.gz hittekaart-a3b378fd66342ecf9a44f814acf1b18a49a05c42.tar.bz2 hittekaart-a3b378fd66342ecf9a44f814acf1b18a49a05c42.zip | |
In the benchmarks, this gives a quite good speed increase, but in
real-life workloads, the speedup is not as stark (from ~66s to ~61s
here).
What is maybe a neat secondary effect here is that we don't end up with
empty tiles, as we only allocate (in tile_mut) when there is a nonzero
pixel to blit. This decreases the number of saved tiles, especially on
larger zooms.
| -rw-r--r-- | hittekaart/src/layer.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/hittekaart/src/layer.rs b/hittekaart/src/layer.rs index 0ab1975..1c860ad 100644 --- a/hittekaart/src/layer.rs +++ b/hittekaart/src/layer.rs @@ -102,7 +102,7 @@ impl<P: Pixel> TileLayer<P> { let source_height = u64::from(source.height()); for tx in x / TILE_WIDTH..=(x + source_width) / TILE_WIDTH { for ty in y / TILE_HEIGHT..=(y + source_height) / TILE_HEIGHT { - let tile = self.tile_mut(tx, ty); + let mut tile = None; let offset_x = (tx * TILE_WIDTH).saturating_sub(x); let offset_y = (ty * TILE_HEIGHT).saturating_sub(y); let local_min_x = x.saturating_sub(tx * TILE_WIDTH); @@ -115,8 +115,13 @@ impl<P: Pixel> TileLayer<P> { let pixel = source .get_pixel(source_x.try_into().unwrap(), source_y.try_into().unwrap()); if pixel.channels() != zero.channels() { - *tile.get_pixel_mut(x.try_into().unwrap(), y.try_into().unwrap()) = - *pixel; + if tile.is_none() { + tile = Some(self.tile_mut(tx, ty)); + } + tile.iter_mut().for_each(|t| { + *t.get_pixel_mut(x.try_into().unwrap(), y.try_into().unwrap()) = + *pixel; + }); } } } |
