Skip to content

remove MutableOpsBufferSupportedLhs and use unsafe mutable_buffer function - #2

Open
alamb wants to merge 1 commit into
rluvaton:add-bitwise-ops-to-boolean-buffer-builderfrom
alamb:alamb/remove_other_trait
Open

alamb wants to merge 1 commit into
rluvaton:add-bitwise-ops-to-boolean-buffer-builderfrom
alamb:alamb/remove_other_trait

Conversation

@alamb

@alamb alamb commented Oct 24, 2025

Copy link
Copy Markdown

This is a proposed simplification for the following PR (merging this PR will update that one):

I will comment inline about the rationale

)]
pub fn mutable_bitwise_bin_op_helper<F>(
left: &mut impl MutableOpsBufferSupportedLhs,
left: &mut MutableBuffer,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Rather than hiding what is going on with pub/hidden traits, I think it is clearer to simply pass in the MutableBuffer here

If you accept this PR and #1 we can avoid the #allow about private bounds as well

/// The caller must ensure that any modifications to the buffer maintain the invariant
/// `self.len < buffer.len() / 8` (that is that the buffer has enough capacity to hold `self.len` bits).
#[inline]
pub unsafe fn mutable_buffer(&mut self) -> &mut MutableBuffer {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I personally think the code is much clearer and easier to understand if make a function that directly exposes the inner MutableBuffer (which is what the trait does) but mark it as unsafe, rather than relying on non public traits

rluvaton pushed a commit that referenced this pull request Feb 4, 2026
# Which issue does this PR close?

small optimization

# Rationale for this change
key insight is the byte clone is cheap just a ref count compare to vec
clone is a alloc + memcopy.

before
```
let mut result = Vec::new();          // alloc #1
result.extend_from_slice(prefix);
result.extend_from_slice(suffix);

let data = Bytes::from(result.clone()); // alloc #2 + memcpy
item.set_from_bytes(data);
self.previous_value = result;          // keep Vec
```

after
```
let mut result = Vec::with_capacity(prefix_len + suffix.len()); // alloc #1
result.extend_from_slice(&self.previous_value[..prefix_len]);
result.extend_from_slice(suffix);

let data = Bytes::from(result);       // no alloc, takes Vec buffer
item.set_from_bytes(data.clone());    // cheap refcount bump
self.previous_value = data;           // move, no alloc
```

# What changes are included in this PR?
previous_value type changed to Bytes
preallocate result vec capacity.

# Are these changes tested?

the existing test should pass

# 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant