Skip to content

feat: Add output: &mut [MaybeUninit<u8>] support - #65

Open
Erouan50 wants to merge 7 commits into
BurntSushi:masterfrom
Erouan50:feat/output-maybe-uninit
Open

feat: Add output: &mut [MaybeUninit<u8>] support#65
Erouan50 wants to merge 7 commits into
BurntSushi:masterfrom
Erouan50:feat/output-maybe-uninit

Conversation

@Erouan50

@Erouan50 Erouan50 commented Apr 1, 2026

Copy link
Copy Markdown

Hello,

This pull request adds new methods to support encoding and decoding with a &mut [MaybeUninit<u8>] as output. It only supports the raw APIs.

The implementation was surprising easy, my only concern is I don't know if raw::Decoder::decompress_uninit() and raw::Encoder::compress_uninit() should be unsafe or not. My opinion is no because calling those methods is safe; the unsafe part is to read the output without truncating it before.

Fixes #62, maybe?

Erouan50 added 2 commits April 1, 2026 16:34
This commit adds new methods to support encoding and decoding with a
`&mut [MaybeUninit<u8>]` as output. It only supports the raw APIs.
@Erouan50 Erouan50 changed the title feat: Add `output: &mut [MaybeUninit<u8>] support feat: Add output: &mut [MaybeUninit<u8>] support Apr 1, 2026
Comment thread src/compress.rs Outdated
Comment thread src/compress.rs Outdated
@NobodyXu

NobodyXu commented Apr 2, 2026

Copy link
Copy Markdown

my only concern is I don't know if raw::Decoder::decompress_uninit() and raw::Encoder::compress_uninit() should be unsafe or not. My opinion is no because calling those methods is safe; the unsafe part is to read the output without truncating it before.

I agree, no such methods should be unsafe as there's nothing inherently unsafe of it

@NobodyXu NobodyXu left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'd say it looks pretty good, but I'm not a maintainer or member so you'd need to get a member to approve jt

@alamb

alamb commented Apr 7, 2026

Copy link
Copy Markdown

Thank you @Erouan50 -- we also would love to use this feature downstream in arrow-rs (see apache/arrow-rs#9583)

@alamb

alamb commented Apr 7, 2026

Copy link
Copy Markdown

Looks like @BurntSushi is the core (only) maintainer of this repo:

Let us know if there is anything we can do to help

@alamb alamb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I also went over this PR carefully (but am not a committer) and it makes sense to me

Comment thread src/compress.rs Outdated
self.compress_uninit(input, output)
}

/// Compresses all bytes in `input` into a freshly allocated `Vec`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think you could reduce the diff (and thus make this PR easier to review) if you didn't move the location of this method

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.

That's fair, I just moved them.

Comment thread src/bytes.rs
let mut i = 0;
while n >= 0b1000_0000 {
data[i] = (n as u8) | 0b1000_0000;
data[i].write((n as u8) | 0b1000_0000);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

looking at this code, I think it could be significantly faster if we (in a follow on PR) omitted the bounds check / verified capacity at a higher level

I think we would need to get profiling to do so

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

@Dandandan

Copy link
Copy Markdown

@BurntSushi do you want to take a look at this?

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.

Could we have an API with output: &mut [MaybeUninit<u8>]?

4 participants