Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
95dc353
Fix documentation for with_capacity and reserve families of methods
jmaargh Apr 9, 2022
b37a05b
rustdoc: optimize loading of source sidebar
jsha Jun 20, 2022
761c846
Add `create_err` and `emit_err` to `ExtCtxt`
beetrees Jun 21, 2022
d6072e5
Add UI test for `cfg!(foo, bar)`
beetrees Jun 21, 2022
6264ffb
Migrate `builtin-macros-requires-cfg-pattern` to `SessionDiagnostic`
beetrees Jun 21, 2022
be5337c
Migrate `builtin-macros-expected-one-cfg-pattern` to `SessionDiagnostic`
beetrees Jun 21, 2022
8e09f42
Update Emscripten's no_default_libraries handling
hoodmane Jun 21, 2022
46b2454
clarify Arc::clone overflow check comment
RalfJung Jun 22, 2022
53481a5
implement `iter_projections` function on `PlaceRef`
rosefromthedead Jun 22, 2022
8e40d93
Filter out keyword items in rustdoc JSON output
GuillaumeGomez Jun 22, 2022
75ad2f7
Add test for keywords in rustdoc JSON output
GuillaumeGomez Jun 22, 2022
96cc0c6
triagebot.toml: Allow applying nominated labels
joshtriplett Jun 22, 2022
5cf5a52
triagebot.toml: Sort and wrap the list of allowed labels
joshtriplett Jun 22, 2022
24e0c44
Update books
ehuss Jun 22, 2022
b96ae9b
Set no_default_libraries: false in wasm32_emscripten target
hoodmane Jun 23, 2022
97f582a
Rollup merge of #96173 - jmaargh:jmaargh/with-capacity-doc-fix, r=Dyl…
matthiaskrgr Jun 23, 2022
960aaea
Rollup merge of #98310 - jsha:defer-source-sidebar, r=GuillaumeGomez
matthiaskrgr Jun 23, 2022
6ed67b7
Rollup merge of #98353 - beetrees:builtin-macros-cfg-diag, r=davidtwco
matthiaskrgr Jun 23, 2022
0252df9
Rollup merge of #98355 - hoodmane:emscripten-no-default, r=petrochenkov
matthiaskrgr Jun 23, 2022
dd97d67
Rollup merge of #98364 - RalfJung:arc-clone, r=Mark-Simulacrum
matthiaskrgr Jun 23, 2022
e9638bf
Rollup merge of #98388 - rosehuds:master, r=davidtwco
matthiaskrgr Jun 23, 2022
665ec8d
Rollup merge of #98390 - GuillaumeGomez:keyword-rustdoc-json, r=notri…
matthiaskrgr Jun 23, 2022
362801a
Rollup merge of #98409 - joshtriplett:triagebot-nominated, r=Mark-Sim…
matthiaskrgr Jun 23, 2022
2ab0edf
Rollup merge of #98410 - ehuss:update-books, r=ehuss
matthiaskrgr Jun 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 29 additions & 22 deletions library/alloc/src/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,11 @@ impl<T: Ord> BinaryHeap<T> {
BinaryHeap { data: vec![] }
}

/// Creates an empty `BinaryHeap` with a specific capacity.
/// This preallocates enough memory for `capacity` elements,
/// so that the `BinaryHeap` does not have to be reallocated
/// until it contains at least that many values.
/// Creates an empty `BinaryHeap` with at least the specified capacity.
///
/// The binary heap will be able to hold at least `capacity` elements without
/// reallocating. This method is allowed to allocate for more elements than
/// `capacity`. If `capacity` is 0, the binary heap will not allocate.
///
/// # Examples
///
Expand Down Expand Up @@ -906,16 +907,18 @@ impl<T> BinaryHeap<T> {
self.data.capacity()
}

/// Reserves the minimum capacity for exactly `additional` more elements to be inserted in the
/// given `BinaryHeap`. Does nothing if the capacity is already sufficient.
/// Reserves the minimum capacity for at least `additional` elements more than
/// the current length. Unlike [`reserve`], this will not
/// deliberately over-allocate to speculatively avoid frequent allocations.
/// After calling `reserve_exact`, capacity will be greater than or equal to
/// `self.len() + additional`. Does nothing if the capacity is already
/// sufficient.
///
/// Note that the allocator may give the collection more space than it requests. Therefore
/// capacity can not be relied upon to be precisely minimal. Prefer [`reserve`] if future
/// insertions are expected.
/// [`reserve`]: BinaryHeap::reserve
///
/// # Panics
///
/// Panics if the new capacity overflows `usize`.
/// Panics if the new capacity overflows [`usize`].
///
/// # Examples
///
Expand All @@ -935,12 +938,15 @@ impl<T> BinaryHeap<T> {
self.data.reserve_exact(additional);
}

/// Reserves capacity for at least `additional` more elements to be inserted in the
/// `BinaryHeap`. The collection may reserve more space to avoid frequent reallocations.
/// Reserves capacity for at least `additional` elements more than the
/// current length. The allocator may reserve more space to speculatively
/// avoid frequent allocations. After calling `reserve`,
/// capacity will be greater than or equal to `self.len() + additional`.
/// Does nothing if capacity is already sufficient.
///
/// # Panics
///
/// Panics if the new capacity overflows `usize`.
/// Panics if the new capacity overflows [`usize`].
///
/// # Examples
///
Expand All @@ -958,10 +964,11 @@ impl<T> BinaryHeap<T> {
self.data.reserve(additional);
}

/// Tries to reserve the minimum capacity for exactly `additional`
/// elements to be inserted in the given `BinaryHeap<T>`. After calling
/// `try_reserve_exact`, capacity will be greater than or equal to
/// `self.len() + additional` if it returns `Ok(())`.
/// Tries to reserve the minimum capacity for at least `additional` elements
/// more than the current length. Unlike [`try_reserve`], this will not
/// deliberately over-allocate to speculatively avoid frequent allocations.
/// After calling `try_reserve_exact`, capacity will be greater than or
/// equal to `self.len() + additional` if it returns `Ok(())`.
/// Does nothing if the capacity is already sufficient.
///
/// Note that the allocator may give the collection more space than it
Expand Down Expand Up @@ -999,11 +1006,11 @@ impl<T> BinaryHeap<T> {
self.data.try_reserve_exact(additional)
}

/// Tries to reserve capacity for at least `additional` more elements to be inserted
/// in the given `BinaryHeap<T>`. The collection may reserve more space to avoid
/// frequent reallocations. After calling `try_reserve`, capacity will be
/// greater than or equal to `self.len() + additional`. Does nothing if
/// capacity is already sufficient.
/// Tries to reserve capacity for at least `additional` elements more than the
/// current length. The allocator may reserve more space to speculatively
/// avoid frequent allocations. After calling `try_reserve`, capacity will be
/// greater than or equal to `self.len() + additional` if it returns
/// `Ok(())`. Does nothing if capacity is already sufficient.
///
/// # Errors
///
Expand Down
16 changes: 8 additions & 8 deletions library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
self.cap() - 1
}

/// Reserves the minimum capacity for exactly `additional` more elements to be inserted in the
/// Reserves the minimum capacity for at least `additional` more elements to be inserted in the
/// given deque. Does nothing if the capacity is already sufficient.
///
/// Note that the allocator may give the collection more space than it requests. Therefore
Expand Down Expand Up @@ -716,7 +716,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
}

/// Reserves capacity for at least `additional` more elements to be inserted in the given
/// deque. The collection may reserve more space to avoid frequent reallocations.
/// deque. The collection may reserve more space to speculatively avoid frequent reallocations.
///
/// # Panics
///
Expand Down Expand Up @@ -748,10 +748,10 @@ impl<T, A: Allocator> VecDeque<T, A> {
}
}

/// Tries to reserve the minimum capacity for exactly `additional` more elements to
/// Tries to reserve the minimum capacity for at least `additional` more elements to
/// be inserted in the given deque. After calling `try_reserve_exact`,
/// capacity will be greater than or equal to `self.len() + additional`.
/// Does nothing if the capacity is already sufficient.
/// capacity will be greater than or equal to `self.len() + additional` if
/// it returns `Ok(())`. Does nothing if the capacity is already sufficient.
///
/// Note that the allocator may give the collection more space than it
/// requests. Therefore, capacity can not be relied upon to be precisely
Expand Down Expand Up @@ -791,10 +791,10 @@ impl<T, A: Allocator> VecDeque<T, A> {
}

/// Tries to reserve capacity for at least `additional` more elements to be inserted
/// in the given deque. The collection may reserve more space to avoid
/// in the given deque. The collection may reserve more space to speculatively avoid
/// frequent reallocations. After calling `try_reserve`, capacity will be
/// greater than or equal to `self.len() + additional`. Does nothing if
/// capacity is already sufficient.
/// greater than or equal to `self.len() + additional` if it returns
/// `Ok(())`. Does nothing if capacity is already sufficient.
///
/// # Errors
///
Expand Down
70 changes: 35 additions & 35 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,13 +455,13 @@ impl String {
String { vec: Vec::new() }
}

/// Creates a new empty `String` with a particular capacity.
/// Creates a new empty `String` with at least the specified capacity.
///
/// `String`s have an internal buffer to hold their data. The capacity is
/// the length of that buffer, and can be queried with the [`capacity`]
/// method. This method creates an empty `String`, but one with an initial
/// buffer that can hold `capacity` bytes. This is useful when you may be
/// appending a bunch of data to the `String`, reducing the number of
/// buffer that can hold at least `capacity` bytes. This is useful when you
/// may be appending a bunch of data to the `String`, reducing the number of
/// reallocations it needs to do.
///
/// [`capacity`]: String::capacity
Expand Down Expand Up @@ -979,21 +979,16 @@ impl String {
self.vec.capacity()
}

/// Ensures that this `String`'s capacity is at least `additional` bytes
/// larger than its length.
///
/// The capacity may be increased by more than `additional` bytes if it
/// chooses, to prevent frequent reallocations.
///
/// If you do not want this "at least" behavior, see the [`reserve_exact`]
/// method.
/// Reserves capacity for at least `additional` bytes more than the
/// current length. The allocator may reserve more space to speculatively
/// avoid frequent allocations. After calling `reserve`,
/// capacity will be greater than or equal to `self.len() + additional`.
/// Does nothing if capacity is already sufficient.
///
/// # Panics
///
/// Panics if the new capacity overflows [`usize`].
///
/// [`reserve_exact`]: String::reserve_exact
///
/// # Examples
///
/// Basic usage:
Expand All @@ -1013,15 +1008,16 @@ impl String {
/// s.push('a');
/// s.push('b');
///
/// // s now has a length of 2 and a capacity of 10
/// // s now has a length of 2 and a capacity of at least 10
/// let capacity = s.capacity();
/// assert_eq!(2, s.len());
/// assert_eq!(10, s.capacity());
/// assert!(capacity >= 10);
///
/// // Since we already have an extra 8 capacity, calling this...
/// // Since we already have at least an extra 8 capacity, calling this...
/// s.reserve(8);
///
/// // ... doesn't actually increase.
/// assert_eq!(10, s.capacity());
/// assert_eq!(capacity, s.capacity());
/// ```
#[cfg(not(no_global_oom_handling))]
#[inline]
Expand All @@ -1030,17 +1026,18 @@ impl String {
self.vec.reserve(additional)
}

/// Ensures that this `String`'s capacity is `additional` bytes
/// larger than its length.
///
/// Consider using the [`reserve`] method unless you absolutely know
/// better than the allocator.
/// Reserves the minimum capacity for at least `additional` bytes more than
/// the current length. Unlike [`reserve`], this will not
/// deliberately over-allocate to speculatively avoid frequent allocations.
/// After calling `reserve_exact`, capacity will be greater than or equal to
/// `self.len() + additional`. Does nothing if the capacity is already
/// sufficient.
///
/// [`reserve`]: String::reserve
///
/// # Panics
///
/// Panics if the new capacity overflows `usize`.
/// Panics if the new capacity overflows [`usize`].
///
/// # Examples
///
Expand All @@ -1061,15 +1058,16 @@ impl String {
/// s.push('a');
/// s.push('b');
///
/// // s now has a length of 2 and a capacity of 10
/// // s now has a length of 2 and a capacity of at least 10
/// let capacity = s.capacity();
/// assert_eq!(2, s.len());
/// assert_eq!(10, s.capacity());
/// assert!(capacity >= 10);
///
/// // Since we already have an extra 8 capacity, calling this...
/// // Since we already have at least an extra 8 capacity, calling this...
/// s.reserve_exact(8);
///
/// // ... doesn't actually increase.
/// assert_eq!(10, s.capacity());
/// assert_eq!(capacity, s.capacity());
/// ```
#[cfg(not(no_global_oom_handling))]
#[inline]
Expand All @@ -1078,11 +1076,11 @@ impl String {
self.vec.reserve_exact(additional)
}

/// Tries to reserve capacity for at least `additional` more elements to be inserted
/// in the given `String`. The collection may reserve more space to avoid
/// frequent reallocations. After calling `reserve`, capacity will be
/// greater than or equal to `self.len() + additional`. Does nothing if
/// capacity is already sufficient.
/// Tries to reserve capacity for at least `additional` bytes more than the
/// current length. The allocator may reserve more space to speculatively
/// avoid frequent allocations. After calling `try_reserve`, capacity will be
/// greater than or equal to `self.len() + additional` if it returns
/// `Ok(())`. Does nothing if capacity is already sufficient.
///
/// # Errors
///
Expand Down Expand Up @@ -1112,9 +1110,11 @@ impl String {
self.vec.try_reserve(additional)
}

/// Tries to reserve the minimum capacity for exactly `additional` more elements to
/// be inserted in the given `String`. After calling `try_reserve_exact`,
/// capacity will be greater than or equal to `self.len() + additional`.
/// Tries to reserve the minimum capacity for at least `additional` bytes
/// more than the current length. Unlike [`try_reserve`], this will not
/// deliberately over-allocate to speculatively avoid frequent allocations.
/// After calling `try_reserve_exact`, capacity will be greater than or
/// equal to `self.len() + additional` if it returns `Ok(())`.
/// Does nothing if the capacity is already sufficient.
///
/// Note that the allocator may give the collection more space than it
Expand Down
Loading