Skip to content

Commit

Permalink
Auto merge of #69743 - ecstatic-morse:rerevert-67174, r=<try>
Browse files Browse the repository at this point in the history
Rerevert "Remove checked_add in Layout::repeat"

This change, which originated in #67174 and was reapplied in #69544, seems to have caused a noticeable slowdown in patched/clean incremental builds (see #69710). Revert it for now while we investigate the underlying issue.

r? @nnethercote
  • Loading branch information
bors committed Mar 10, 2020
2 parents dd155df + 04e9877 commit 0f376b8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/libcore/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,18 @@ impl Layout {
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
#[inline]
pub fn repeat(&self, n: usize) -> Result<(Self, usize), LayoutErr> {
// This cannot overflow. Quoting from the invariant of Layout:
// `padded_size` cannot overflow. Quoting from the invariant of Layout:
// > `size`, when rounded up to the nearest multiple of `align`,
// > must not overflow (i.e., the rounded value must be less than
// > `usize::MAX`)
let padded_size = self.size() + self.padding_needed_for(self.align());
//
// However, replacing this line with an `unchecked_add` or a regular `+`
// operator caused a noticeable slowdown, see #69710.
let padded_size = self
.size()
.checked_add(self.padding_needed_for(self.align()))
.ok_or(LayoutErr { private: () })?;

let alloc_size = padded_size.checked_mul(n).ok_or(LayoutErr { private: () })?;

unsafe {
Expand Down

0 comments on commit 0f376b8

Please sign in to comment.