Skip to content

Change occurances of truncate(0) to clear#9593

Closed
Rafferty97 wants to merge 1 commit intoapache:mainfrom
Rafferty97:truncate-zero
Closed

Change occurances of truncate(0) to clear#9593
Rafferty97 wants to merge 1 commit intoapache:mainfrom
Rafferty97:truncate-zero

Conversation

@Rafferty97
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

In response to a comment on #9494, I have searched for occurances of truncate(0) and replaced them with clear to be more idiomatic. I know it's only a minor stylistic change, but it does help with code readability.

In the process, I also noticed and fixed an inconsistency between MutableBuffer::truncate and MutableBuffer::clear. Not sure if this is a latent bug or actually benign.

Rationale for this change

Explained above

What changes are included in this PR?

  • Replace a few instances of truncate(0) with clear
  • Fix MutableBuffer::clear to be consistent with MutableBuffer::truncate

Are these changes tested?

Yes, the existing test suite passes.

Are there any user-facing changes?

No

@github-actions github-actions bot added parquet Changes to the parquet crate arrow Changes to the arrow crate labels Mar 20, 2026
Copy link
Copy Markdown
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Rafferty97

Comment thread arrow-buffer/src/buffer/mutable.rs Outdated
pub fn clear(&mut self) {
self.len = 0
self.len = 0;
#[cfg(feature = "pool")]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this sees unrelated (though a good change)

I think we should either have a test for this or remove it from the PR (maybe it would be good as a follow on PR -- I am not sure if there are other places where something similar should be)

Copy link
Copy Markdown
Contributor Author

@Rafferty97 Rafferty97 Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, this wasn't my change. Something must've gone funny when rebasing or something.

Ah, actually, I did make this change. I'll separate it into a follow on PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alamb Okay, so it turns out that the two changes are actually somewhat interdependent. When I changed the line buffer.truncate(0) to buffer.clear in the unit test test_truncate_with_pool, this test breaks due to the missing code in the implementation of clear that is present in truncate. So, as it stands, this PR by itself breaks a unit test. I've created a new PR (#9622) that fixes this, which also includes the changes from this PR.

For the sake of simplicity, I suggest that this PR be closed and #9622 be merged.

@Rafferty97 Rafferty97 requested a review from alamb March 29, 2026 07:16
@alamb alamb closed this in #9622 Mar 31, 2026
alamb pushed a commit that referenced this pull request Mar 31, 2026
# 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate parquet Changes to the parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants