1
Fork 0

Auto merge of #75621 - TimDiekmann:no-fast-realloc, r=Amanieu

Remove fast path in reallocation for same layout sizes

r? @Amanieu

Before merging a perf-run should be done.

Closes https://github.com/rust-lang/wg-allocators/issues/70
This commit is contained in:
bors 2020-08-18 05:42:05 +00:00
commit 515c9fa505
3 changed files with 20 additions and 52 deletions

View file

@ -163,8 +163,6 @@ pub unsafe trait AllocRef {
/// * `new_size` must be greater than or equal to `layout.size()`, and
/// * `new_size`, when rounded up to the nearest multiple of `layout.align()`, must not overflow
/// (i.e., the rounded value must be less than or equal to `usize::MAX`).
// Note: We can't require that `new_size` is strictly greater than `layout.size()` because of ZSTs.
// alternative: `new_size` must be strictly greater than `layout.size()` or both are zero
///
/// [*currently allocated*]: #currently-allocated-memory
/// [*fit*]: #memory-fitting
@ -194,10 +192,6 @@ pub unsafe trait AllocRef {
"`new_size` must be greater than or equal to `layout.size()`"
);
if size == new_size {
return Ok(NonNull::slice_from_raw_parts(ptr, size));
}
let new_layout =
// SAFETY: the caller must ensure that the `new_size` does not overflow.
// `layout.align()` comes from a `Layout` and is thus guaranteed to be valid for a Layout.
@ -238,8 +232,6 @@ pub unsafe trait AllocRef {
/// * `new_size` must be greater than or equal to `layout.size()`, and
/// * `new_size`, when rounded up to the nearest multiple of `layout.align()`, must not overflow
/// (i.e., the rounded value must be less than or equal to `usize::MAX`).
// Note: We can't require that `new_size` is strictly greater than `layout.size()` because of ZSTs.
// alternative: `new_size` must be strictly greater than `layout.size()` or both are zero
///
/// [*currently allocated*]: #currently-allocated-memory
/// [*fit*]: #memory-fitting
@ -269,10 +261,6 @@ pub unsafe trait AllocRef {
"`new_size` must be greater than or equal to `layout.size()`"
);
if size == new_size {
return Ok(NonNull::slice_from_raw_parts(ptr, size));
}
let new_layout =
// SAFETY: the caller must ensure that the `new_size` does not overflow.
// `layout.align()` comes from a `Layout` and is thus guaranteed to be valid for a Layout.
@ -315,8 +303,6 @@ pub unsafe trait AllocRef {
/// * `ptr` must denote a block of memory [*currently allocated*] via this allocator,
/// * `layout` must [*fit*] that block of memory (The `new_size` argument need not fit it.), and
/// * `new_size` must be smaller than or equal to `layout.size()`.
// Note: We can't require that `new_size` is strictly smaller than `layout.size()` because of ZSTs.
// alternative: `new_size` must be smaller than `layout.size()` or both are zero
///
/// [*currently allocated*]: #currently-allocated-memory
/// [*fit*]: #memory-fitting
@ -346,10 +332,6 @@ pub unsafe trait AllocRef {
"`new_size` must be smaller than or equal to `layout.size()`"
);
if size == new_size {
return Ok(NonNull::slice_from_raw_parts(ptr, size));
}
let new_layout =
// SAFETY: the caller must ensure that the `new_size` does not overflow.
// `layout.align()` comes from a `Layout` and is thus guaranteed to be valid for a Layout.