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

Help the compiler optimize our mapping code #19

Open
woodruffw opened this issue Jan 18, 2022 · 0 comments
Open

Help the compiler optimize our mapping code #19

woodruffw opened this issue Jan 18, 2022 · 0 comments

Comments

@woodruffw
Copy link
Owner

rustc can recognize the following pattern:

assert!(slice.len() >= SOMETHING);

let _ = slice[0];
let _ = slice[1..N];

...and emit only one bounds check (for the initial assert!) instead of one per index/slice operation. We make heavy use of individual/slice indexing throughout the mapper, so we should use assert! judiciously wherever we can.

That being said, we should make sure that our current pattern isn't already providing this optimization, namely:

        if fields.len() < 10 {
            return Err(FunctionError::TooShort(fields.len()));
        }
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

1 participant