Skip to content

Commit 1a169cd

Browse files
authored
Fix MutableBuffer::clear (#9622)
# Which issue does this PR close? - closes #9593 # Rationale for this change In a previous PR (#9593), I change instances of `truncate(0)` to `clear()`. However, this breaks the test `test_truncate_with_pool` at `arrow-buffer/src/buffer/mutable.rs:1357`, due to an inconsistency between the implementation of `truncate` and `clear`. This PR fixes that test. # What changes are included in this PR? This PR copies a section of code related to the `pool` feature present in `truncate` but absent in `clear`, fixing the failing unit test. # Are these changes tested? Yes. # Are there any user-facing changes? No.
1 parent 77e4d05 commit 1a169cd

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

arrow-buffer/src/buffer/mutable.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,13 @@ impl MutableBuffer {
450450

451451
/// Clear all existing data from this buffer.
452452
pub fn clear(&mut self) {
453-
self.len = 0
453+
self.len = 0;
454+
#[cfg(feature = "pool")]
455+
{
456+
if let Some(reservation) = self.reservation.lock().unwrap().as_mut() {
457+
reservation.resize(self.len);
458+
}
459+
}
454460
}
455461

456462
/// Returns the data stored in this buffer as a slice.
@@ -1371,7 +1377,7 @@ mod tests {
13711377
assert_eq!(pool.used(), 40);
13721378

13731379
// Truncate to zero
1374-
buffer.truncate(0);
1380+
buffer.clear();
13751381
assert_eq!(buffer.len(), 0);
13761382
assert_eq!(pool.used(), 0);
13771383
}

arrow-json/src/reader/value_iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl<R: BufRead> Iterator for ValueIter<R> {
7373
}
7474

7575
loop {
76-
self.line_buf.truncate(0);
76+
self.line_buf.clear();
7777
match self.reader.read_line(&mut self.line_buf) {
7878
Ok(0) => {
7979
// read_line returns 0 when stream reached EOF

parquet/tests/geospatial.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ mod test {
380380

381381
for i in 0..reader.num_row_groups() {
382382
let row_group = reader.get_row_group(i).unwrap();
383-
values.truncate(0);
384-
def_levels.truncate(0);
383+
values.clear();
384+
def_levels.clear();
385385

386386
let mut row_group_out = writer.next_row_group().unwrap();
387387

0 commit comments

Comments
 (0)