Skip to content

Commit

Permalink
fix: Reserve the correct number of elements when retrieving string
Browse files Browse the repository at this point in the history
…or `bytes` array elements
  • Loading branch information
LDeakin committed Mar 2, 2025
1 parent a577d37 commit ca16d79
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `{Array,Group}::[async_]open[_opt]` continue to fail with additional fields with `"must_understand": true`
- Bump `derive_more` to 0.2.0

### Fixed
- Fixed reserving one more element than necessary when retrieving `string` or `bytes` array elements

## [0.19.2] - 2025-02-13

### Changed
Expand Down
4 changes: 2 additions & 2 deletions zarrs/src/array/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl ElementOwned for String {
) -> Result<Vec<Self>, ArrayError> {
Self::validate_data_type(data_type)?;
let (bytes, offsets) = bytes.into_variable()?;
let mut elements = Vec::with_capacity(offsets.len());
let mut elements = Vec::with_capacity(offsets.len().saturating_sub(1));
for (curr, next) in offsets.iter().tuple_windows() {
elements.push(
Self::from_utf8(bytes[*curr..*next].to_vec())
Expand Down Expand Up @@ -276,7 +276,7 @@ impl ElementOwned for Vec<u8> {
) -> Result<Vec<Self>, ArrayError> {
Self::validate_data_type(data_type)?;
let (bytes, offsets) = bytes.into_variable()?;
let mut elements = Vec::with_capacity(offsets.len());
let mut elements = Vec::with_capacity(offsets.len().saturating_sub(1));
for (curr, next) in offsets.iter().tuple_windows() {
elements.push(bytes[*curr..*next].to_vec());
}
Expand Down

0 comments on commit ca16d79

Please sign in to comment.