Commit 67e3f87
committed
Auto merge of #341 - JustForFun88:edit_do_alloc, r=Amanieu
Editing `do_alloc` for reducing LLVM IR
1. I think this will speed up compilation, since one way or another everything will come down to this code (but I didn’t compare performance).
2. I don’t know if the compiler was able to optimize that old code, but it literally checked the same thing twice (due to `map` and `map_err` in a row, and roughly speaking it came down to:
```rust
pub fn do_alloc<A: Allocator>(alloc: &A, layout: Layout) -> Result<NonNull<u8>, ()> {
match match alloc.allocate(layout) {
Ok(ptr) => Ok(ptr.as_non_null_ptr()),
Err(e) => Err(e),
} {
Ok(ptr) => Ok(ptr),
Err(_) => Err(()),
}
}
```
And when the code is written explicitly, it is immediately clear that it looks strange. And why force the compiler to think beyond the need?
3. And finally, in my opinion, the readability of the code has not only not decreased, but even increased.1 file changed
+4
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
0 commit comments