Skip to content
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

Make performance description of String::insert_str more precise #138538

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
@@ -1725,8 +1725,8 @@ impl String {

/// Inserts a string slice into this `String` at a byte position.
///
/// This is an *O*(*n*) operation as it requires copying every element in the
/// buffer.
/// If there is space in `self` this will copy `self.len() - idx + string.len()` bytes,
/// otherwise will reallocate and copy `self.len() + string.len()` bytes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect – the reallocation case potentially copies self.capacity() bytes and then additionally self.len() - idx + string.len() bytes.

///
/// # Panics
///
Loading