Skip to content

Make performance description of String::{insert,insert_str,remove} more precise #138538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2025
Merged
Changes from all commits
Commits
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
25 changes: 16 additions & 9 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down Expand Up @@ -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
///
Expand Down Expand Up @@ -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
///
Expand Down
Loading