Skip to content

Remove BufferSupportedRhs in favor of AsRef<[u8]> - #1

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

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

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):

/// This is because we don't want this trait to expose the inner buffer to the public.
/// this is the trait implementor choice.
///
pub(crate) trait BufferSupportedRhs {

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 think this trait is the same as the built in AsRef<[u8]> , so I propose reusing that trait

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