Skip to content

Add RingBuf::as_slices #19159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bfops opened this issue Nov 20, 2014 · 6 comments
Closed

Add RingBuf::as_slices #19159

bfops opened this issue Nov 20, 2014 · 6 comments

Comments

@bfops
Copy link
Contributor

bfops commented Nov 20, 2014

It would be nice to have something like pub fn as_slices(&'a self) -> (&'a [T], &'a [T]) for bulk access of RingBuf data (e.g. for supplying to OpenGL without lots of glBufferSubData calls and without copying to an intermediate buffer).

@Gankra
Copy link
Contributor

Gankra commented Nov 20, 2014

I think this is a pretty good idea. I've also considered the possibility of a potentially more expensive method that ensures that the contents are all contiguous, and then spits out a single slice, so that you can use all the slice utilities. Would that be useful to you?

@Gankra
Copy link
Contributor

Gankra commented Nov 20, 2014

CC @aturon

@bfops
Copy link
Contributor Author

bfops commented Nov 20, 2014

I need to be able to handle the case where it's not contiguous, so would that mean the code ends up looking something like:

match buf.as_slice() {
    // contents are contiguous
    Some(slice) => {
        do_things(slice);
    }
    // contents aren't contiguous
    None => {
        let (slice1, slice2) = buf.as_slices();
        do_things(slice1);
        do_things(slice2);
    }

It would save the work of constructing an extra slice when it's unnecessary, but would it add branching in the rest of the cases? Would it be more or less performant to return something like:

enum RingBufSlice<'a, T> {
    Contiguous(&'a [T]),
    Split((&'a [T], &'a [T])),
}

@huonw huonw added the A-libs label Nov 21, 2014
@aturon
Copy link
Member

aturon commented Nov 21, 2014

@gankro I'm happy to see a method like this land.

@Gankra
Copy link
Contributor

Gankra commented Nov 21, 2014

I'll add it to the hypothetical collections reform part 2.

@bfops
Copy link
Contributor Author

bfops commented Dec 24, 2014

Closed in #19903. Thanks everybody!

@bfops bfops closed this as completed Dec 24, 2014
lnicola pushed a commit to lnicola/rust that referenced this issue Feb 17, 2025
fix: Set `RUSTUP_TOOLCHAIN` when loading sysroot workspace
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

No branches or pull requests

4 participants