Skip to content

Commit 0f376b8

Browse files
committed
Auto merge of #69743 - ecstatic-morse:rerevert-67174, r=<try>
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
2 parents dd155df + 04e9877 commit 0f376b8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/libcore/alloc.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,18 @@ impl Layout {
247247
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
248248
#[inline]
249249
pub fn repeat(&self, n: usize) -> Result<(Self, usize), LayoutErr> {
250-
// This cannot overflow. Quoting from the invariant of Layout:
250+
// `padded_size` cannot overflow. Quoting from the invariant of Layout:
251251
// > `size`, when rounded up to the nearest multiple of `align`,
252252
// > must not overflow (i.e., the rounded value must be less than
253253
// > `usize::MAX`)
254-
let padded_size = self.size() + self.padding_needed_for(self.align());
254+
//
255+
// However, replacing this line with an `unchecked_add` or a regular `+`
256+
// operator caused a noticeable slowdown, see #69710.
257+
let padded_size = self
258+
.size()
259+
.checked_add(self.padding_needed_for(self.align()))
260+
.ok_or(LayoutErr { private: () })?;
261+
255262
let alloc_size = padded_size.checked_mul(n).ok_or(LayoutErr { private: () })?;
256263

257264
unsafe {

0 commit comments

Comments
 (0)