diff options
| author | Jubilee <workingjubilee@gmail.com> | 2025-06-17 00:28:13 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-17 00:28:13 -0700 |
| commit | 346adcef4faa2481b9f778ea53b1304a34887b43 (patch) | |
| tree | 0d9cf07cf6a2f3837e968acdca0422ae6f990114 /library/alloc | |
| parent | 55d436467c351b56253deeba209ae2553d1c243f (diff) | |
| parent | 0348a4a717d56c22a8c3b78738823342e505f424 (diff) | |
| download | rust-346adcef4faa2481b9f778ea53b1304a34887b43.tar.gz rust-346adcef4faa2481b9f778ea53b1304a34887b43.zip | |
Rollup merge of #138538 - hkBst:patch-4, r=tgross35
Make performance description of String::{insert,insert_str,remove} more precise
Diffstat (limited to 'library/alloc')
| -rw-r--r-- | library/alloc/src/string.rs | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index 37614a7ca45..7c71594c430 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -1489,10 +1489,11 @@ impl String { Some(ch) } - /// Removes a [`char`] from this `String` at a byte position and returns it. + /// Removes a [`char`] from this `String` at byte position `idx` and returns it. /// - /// This is an *O*(*n*) operation, as it requires copying every element in the - /// buffer. + /// Copies all bytes after the removed char to new positions. + /// + /// Note that calling this in a loop can result in quadratic behavior. /// /// # Panics /// @@ -1678,10 +1679,13 @@ impl String { drop(guard); } - /// Inserts a character into this `String` at a byte position. + /// Inserts a character into this `String` at byte position `idx`. + /// + /// Reallocates if `self.capacity()` is insufficient, which may involve copying all + /// `self.capacity()` bytes. Makes space for the insertion by copying all bytes of + /// `&self[idx..]` to new positions. /// - /// This is an *O*(*n*) operation as it requires copying every element in the - /// buffer. + /// Note that calling this in a loop can result in quadratic behavior. /// /// # Panics /// @@ -1733,10 +1737,13 @@ impl String { } } - /// Inserts a string slice into this `String` at a byte position. + /// Inserts a string slice into this `String` at byte position `idx`. + /// + /// Reallocates if `self.capacity()` is insufficient, which may involve copying all + /// `self.capacity()` bytes. Makes space for the insertion by copying all bytes of + /// `&self[idx..]` to new positions. /// - /// This is an *O*(*n*) operation as it requires copying every element in the - /// buffer. + /// Note that calling this in a loop can result in quadratic behavior. /// /// # Panics /// |
