Skip to content
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

Add convenience method for converting a Range to a start and end index #1971

Open
lopopolo opened this issue Jul 24, 2022 · 0 comments
Open
Labels
A-vm Area: Interpreter VM implementations. C-enhancement Category: New feature or request. C-quality Category: Refactoring, cleanup, and quality improvements.

Comments

@lopopolo
Copy link
Member

Pretty nice refactorings. I've got a couple of questions around the sys::mrb_range_beg_len and a couple of tests for byteslice that could be added.

I'm wondering whether something like this would ever make sense:

impl for Range {
    pub fn array_accessor(interp: &mut Artichoke, cap: Option<Value>) -> (usize, usize) {
        match Range {
            Range::Valid { start, len } => {
                  //do all the checking of start/len against the cap
                  (start, len)
            },
            _ => Err()
        }
    }
}

☝️ Something that does all the conversion to usize, and just returns the elements to pluck out of a list. I don't think there's anything particular special about a range, except it gives you many ways to access elements in an array in this case.

I'm approving since I don't see anything in particular that could/should break.

Originally posted by @b-n in #1958 (review)

@lopopolo lopopolo added C-enhancement Category: New feature or request. A-vm Area: Interpreter VM implementations. C-quality Category: Refactoring, cleanup, and quality improvements. labels Jul 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-vm Area: Interpreter VM implementations. C-enhancement Category: New feature or request. C-quality Category: Refactoring, cleanup, and quality improvements.
Development

No branches or pull requests

1 participant