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

core: Remove panics from some Layout methods #49884

Merged
merged 1 commit into from
Apr 15, 2018

Commits on Apr 13, 2018

  1. core: Remove panics from some Layout methods

    `Layout` is often used at the core of allocation APIs and is as a result pretty
    sensitive to codegen in various circumstances. I was profiling `-C opt-level=z`
    with a wasm project recently and noticed that the `unwrap()` wasn't removed
    inside of `Layout`, causing the program to be much larger than it otherwise
    would be. If inlining were more aggressive LLVM would have figured out that the
    panic could be eliminated, but in general the methods here can't panic in the
    first place!
    
    As a result this commit makes the following tweaks:
    
    * Removes `unwrap()` and replaces it with `unsafe` in `Layout::new` and
      `Layout::for_value`. For posterity though a debug assertion was left behind.
    * Removes an `unwrap()` in favor of `?` in the `repeat` method. The comment
      indicating that the function call couldn't panic wasn't quite right in that if
      `alloc_size` becomes too large and if `align` is high enough it could indeed
      cause a panic.
    
    This'll hopefully mean that panics never get introduced into code in the first
    place, ensuring that `opt-level=z` is closer to `opt-level=s` in this regard.
    alexcrichton committed Apr 13, 2018
    Configuration menu
    Copy the full SHA
    68e555b View commit details
    Browse the repository at this point in the history