Skip to content

Commit

Permalink
Remove an unnecessary allocation in IndicesIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
LDeakin committed Feb 26, 2024
1 parent 4eba5e0 commit 50a2460
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Disabled `blosc` codec partial decoding

### Fixed
- Remove an unnecessary allocation in `IndicesIterator`

## [0.12.1] - 2024-02-24

### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zarrs"
version = "0.12.1"
version = "0.12.2"
authors = ["Lachlan Deakin <ljdgit@gmail.com>"]
edition = "2021"
rust-version = "1.71"
Expand Down
18 changes: 6 additions & 12 deletions src/array_subset/iterators/indices_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,9 @@ impl Iterator for IndicesIterator<'_> {
type Item = ArrayIndices;

fn next(&mut self) -> Option<Self::Item> {
let indices = std::iter::zip(
unravel_index(self.index_front, self.subset.shape()).iter(),
self.subset.start(),
)
.map(|(index, start)| index + start)
.collect::<Vec<_>>();
let mut indices = unravel_index(self.index_front, self.subset.shape());
std::iter::zip(indices.iter_mut(), self.subset.start())
.for_each(|(index, start)| *index += start);

if self.index_front < self.index_back {
self.index_front += 1;
Expand All @@ -166,12 +163,9 @@ impl DoubleEndedIterator for IndicesIterator<'_> {
fn next_back(&mut self) -> Option<Self::Item> {
if self.index_back > self.index_front {
self.index_back -= 1;
let indices = std::iter::zip(
unravel_index(self.index_back, self.subset.shape()).iter(),
self.subset.start(),
)
.map(|(index, start)| index + start)
.collect::<Vec<_>>();
let mut indices = unravel_index(self.index_back, self.subset.shape());
std::iter::zip(indices.iter_mut(), self.subset.start())
.for_each(|(index, start)| *index += start);
Some(indices)
} else {
None
Expand Down

0 comments on commit 50a2460

Please sign in to comment.