Skip to content

Add inline to every String function #20859

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
Jan 11, 2015
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
15 changes: 15 additions & 0 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ impl String {
/// assert_eq!(String::from_utf16_lossy(v),
/// "𝄞mus\u{FFFD}ic\u{FFFD}".to_string());
/// ```
#[inline]
#[stable]
pub fn from_utf16_lossy(v: &[u16]) -> String {
unicode_str::utf16_items(v).map(|c| c.to_char_lossy()).collect()
Expand Down Expand Up @@ -556,6 +557,7 @@ impl String {
/// assert_eq!(s.remove(1), 'o');
/// assert_eq!(s.remove(0), 'o');
/// ```
#[inline]
#[stable]
pub fn remove(&mut self, idx: uint) -> char {
let len = self.len();
Expand All @@ -582,6 +584,7 @@ impl String {
///
/// If `idx` does not lie on a character boundary or is out of bounds, then
/// this function will panic.
#[inline]
#[stable]
pub fn insert(&mut self, idx: uint, ch: char) {
let len = self.len();
Expand Down Expand Up @@ -618,6 +621,7 @@ impl String {
/// }
/// assert_eq!(s.as_slice(), "olleh");
/// ```
#[inline]
#[stable]
pub unsafe fn as_mut_vec<'a>(&'a mut self) -> &'a mut Vec<u8> {
&mut self.vec
Expand Down Expand Up @@ -645,6 +649,7 @@ impl String {
/// v.push('a');
/// assert!(!v.is_empty());
/// ```
#[inline]
#[stable]
pub fn is_empty(&self) -> bool { self.len() == 0 }

Expand Down Expand Up @@ -801,6 +806,7 @@ impl Str for String {

#[stable]
impl Default for String {
#[inline]
#[stable]
fn default() -> String {
String::new()
Expand All @@ -809,13 +815,15 @@ impl Default for String {

#[stable]
impl fmt::String for String {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::String::fmt(&**self, f)
}
}

#[unstable = "waiting on fmt stabilization"]
impl fmt::Show for String {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Show::fmt(&**self, f)
}
Expand All @@ -842,6 +850,7 @@ impl<H: hash::Writer + hash::Hasher> hash::Hash<H> for String {
impl<'a> Add<&'a str> for String {
type Output = String;

#[inline]
fn add(mut self, other: &str) -> String {
self.push_str(other);
self
Expand Down Expand Up @@ -881,6 +890,7 @@ impl ops::Index<ops::FullRange> for String {
impl ops::Deref for String {
type Target = str;

#[inline]
fn deref<'a>(&'a self) -> &'a str {
unsafe { mem::transmute(&self.vec[]) }
}
Expand All @@ -895,6 +905,7 @@ pub struct DerefString<'a> {
impl<'a> Deref for DerefString<'a> {
type Target = String;

#[inline]
fn deref<'b>(&'b self) -> &'b String {
unsafe { mem::transmute(&*self.x) }
}
Expand Down Expand Up @@ -933,6 +944,7 @@ pub trait ToString {
}

impl<T: fmt::String + ?Sized> ToString for T {
#[inline]
fn to_string(&self) -> String {
use core::fmt::Writer;
let mut buf = String::new();
Expand All @@ -943,12 +955,14 @@ impl<T: fmt::String + ?Sized> ToString for T {
}

impl IntoCow<'static, String, str> for String {
#[inline]
fn into_cow(self) -> CowString<'static> {
Cow::Owned(self)
}
}

impl<'a> IntoCow<'a, String, str> for &'a str {
#[inline]
fn into_cow(self) -> CowString<'a> {
Cow::Borrowed(self)
}
Expand All @@ -966,6 +980,7 @@ impl<'a> Str for CowString<'a> {
}

impl fmt::Writer for String {
#[inline]
fn write_str(&mut self, s: &str) -> fmt::Result {
self.push_str(s);
Ok(())
Expand Down