diff options
| author | bors <bors@rust-lang.org> | 2017-12-10 00:57:40 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-12-10 00:57:40 +0000 |
| commit | c89e206eedee079c4620eacbfb4e3bc6cf392fc8 (patch) | |
| tree | d362e737537921ce60a13c88139b708e63e29a01 /src/liballoc/allocator.rs | |
| parent | 8db163e53dab4f188a60bf24b4d6ebeb1ea5cab1 (diff) | |
| parent | 3024c1434a667425d30e4b0785857381323712aa (diff) | |
| download | rust-c89e206eedee079c4620eacbfb4e3bc6cf392fc8.tar.gz rust-c89e206eedee079c4620eacbfb4e3bc6cf392fc8.zip | |
Auto merge of #46602 - mbrubeck:try, r=kennytm
Replace option_try macros and match with ? operator None
Diffstat (limited to 'src/liballoc/allocator.rs')
| -rw-r--r-- | src/liballoc/allocator.rs | 46 |
1 files changed, 9 insertions, 37 deletions
diff --git a/src/liballoc/allocator.rs b/src/liballoc/allocator.rs index 3a2022ad429..c2a8f5f8ff9 100644 --- a/src/liballoc/allocator.rs +++ b/src/liballoc/allocator.rs @@ -217,14 +217,8 @@ impl Layout { /// On arithmetic overflow, returns `None`. #[inline] pub fn repeat(&self, n: usize) -> Option<(Self, usize)> { - let padded_size = match self.size.checked_add(self.padding_needed_for(self.align)) { - None => return None, - Some(padded_size) => padded_size, - }; - let alloc_size = match padded_size.checked_mul(n) { - None => return None, - Some(alloc_size) => alloc_size, - }; + let padded_size = self.size.checked_add(self.padding_needed_for(self.align))?; + let alloc_size = padded_size.checked_mul(n)?; // We can assume that `self.align` is a power-of-two that does // not exceed 2<sup>31</sup>. Furthermore, `alloc_size` has already been @@ -246,26 +240,14 @@ impl Layout { /// On arithmetic overflow, returns `None`. pub fn extend(&self, next: Self) -> Option<(Self, usize)> { let new_align = cmp::max(self.align, next.align); - let realigned = match Layout::from_size_align(self.size, new_align) { - None => return None, - Some(l) => l, - }; + let realigned = Layout::from_size_align(self.size, new_align)?; let pad = realigned.padding_needed_for(next.align); - let offset = match self.size.checked_add(pad) { - None => return None, - Some(offset) => offset, - }; - let new_size = match offset.checked_add(next.size) { - None => return None, - Some(new_size) => new_size, - }; + let offset = self.size.checked_add(pad)?; + let new_size = offset.checked_add(next.size)?; - let layout = match Layout::from_size_align(new_size, new_align) { - None => return None, - Some(l) => l, - }; + let layout = Layout::from_size_align(new_size, new_align)?; Some((layout, offset)) } @@ -282,11 +264,7 @@ impl Layout { /// /// On arithmetic overflow, returns `None`. pub fn repeat_packed(&self, n: usize) -> Option<Self> { - let size = match self.size().checked_mul(n) { - None => return None, - Some(scaled) => scaled, - }; - + let size = self.size().checked_mul(n)?; Layout::from_size_align(size, self.align) } @@ -306,14 +284,8 @@ impl Layout { /// /// On arithmetic overflow, returns `None`. pub fn extend_packed(&self, next: Self) -> Option<(Self, usize)> { - let new_size = match self.size().checked_add(next.size()) { - None => return None, - Some(new_size) => new_size, - }; - let layout = match Layout::from_size_align(new_size, self.align) { - None => return None, - Some(l) => l, - }; + let new_size = self.size().checked_add(next.size())?; + let layout = Layout::from_size_align(new_size, self.align)?; Some((layout, self.size())) } |
