Skip to content

Commit

Permalink
libcollections: Inline some performance-critical string functions; e.g.
Browse files Browse the repository at this point in the history
`chars()`.

This was showing up in Servo profiles.
  • Loading branch information
pcwalton committed Jul 28, 2015
1 parent ba9224f commit 3a12b4c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/libcollections/str.rs
Expand Up @@ -425,6 +425,7 @@ impl str {
since = "1.0.0")]
#[unstable(feature = "unicode",
reason = "this functionality may only be provided by libunicode")]
#[inline]
pub fn width(&self, is_cjk: bool) -> usize {
UnicodeStr::width(self, is_cjk)
}
Expand Down Expand Up @@ -459,6 +460,7 @@ impl str {
with the existence of the char_indices iterator or \
this method may want to be replaced with checked \
slicing")]
#[inline]
pub fn is_char_boundary(&self, index: usize) -> bool {
core_str::StrExt::is_char_boundary(self, index)
}
Expand Down Expand Up @@ -514,6 +516,7 @@ impl str {
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub unsafe fn slice_unchecked(&self, begin: usize, end: usize) -> &str {
core_str::StrExt::slice_unchecked(self, begin, end)
}
Expand All @@ -522,6 +525,7 @@ impl str {
///
/// Same as `slice_unchecked`, but works with `&mut str` instead of `&str`.
#[unstable(feature = "str_slice_mut", reason = "recently added")]
#[inline]
pub unsafe fn slice_mut_unchecked(&mut self, begin: usize, end: usize) -> &mut str {
core_str::StrExt::slice_mut_unchecked(self, begin, end)
}
Expand Down Expand Up @@ -556,6 +560,7 @@ impl str {
#[deprecated(since = "1.3.0",
reason = "can be implemented with char_indices and \
hasn't seen enough use to justify inclusion")]
#[inline]
pub fn slice_chars(&self, begin: usize, end: usize) -> &str {
core_str::StrExt::slice_chars(self, begin, end)
}
Expand Down Expand Up @@ -608,6 +613,7 @@ impl str {
reason = "often replaced by char_indices, this method may \
be removed in favor of just char_at() or eventually \
removed altogether")]
#[inline]
pub fn char_range_at(&self, start: usize) -> CharRange {
core_str::StrExt::char_range_at(self, start)
}
Expand Down Expand Up @@ -665,6 +671,7 @@ impl str {
reason = "often replaced by char_indices, this method may \
be removed in favor of just char_at_reverse() or \
eventually removed altogether")]
#[inline]
pub fn char_range_at_reverse(&self, start: usize) -> CharRange {
core_str::StrExt::char_range_at_reverse(self, start)
}
Expand All @@ -691,6 +698,7 @@ impl str {
future; it is normally replaced by chars/char_indices \
iterators or by getting the first char from a \
subslice")]
#[inline]
pub fn char_at(&self, i: usize) -> char {
core_str::StrExt::char_at(self, i)
}
Expand All @@ -716,6 +724,7 @@ impl str {
reason = "see char_at for more details, but reverse semantics \
are also somewhat unclear, especially with which \
cases generate panics")]
#[inline]
pub fn char_at_reverse(&self, i: usize) -> char {
core_str::StrExt::char_at_reverse(self, i)
}
Expand Down Expand Up @@ -749,6 +758,7 @@ impl str {
reason = "awaiting conventions about shifting and slices and \
may not be warranted with the existence of the chars \
and/or char_indices iterators")]
#[inline]
pub fn slice_shift_char(&self) -> Option<(char, &str)> {
core_str::StrExt::slice_shift_char(self)
}
Expand Down Expand Up @@ -810,6 +820,7 @@ impl str {
/// '\u{1f1e8}', '\u{1f1ed}', ' ', '한']);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn chars(&self) -> Chars {
core_str::StrExt::chars(self)
}
Expand All @@ -825,6 +836,7 @@ impl str {
/// assert_eq!(v, b);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn char_indices(&self) -> CharIndices {
core_str::StrExt::char_indices(self)
}
Expand All @@ -839,6 +851,7 @@ impl str {
/// assert_eq!(v, b"bors".to_vec());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn bytes(&self) -> Bytes {
core_str::StrExt::bytes(self)
}
Expand All @@ -855,6 +868,7 @@ impl str {
/// assert_eq!(v, ["Mary", "had", "a", "little", "lamb"]);
/// ```
#[stable(feature = "split_whitespace", since = "1.1.0")]
#[inline]
pub fn split_whitespace(&self) -> SplitWhitespace {
UnicodeStr::split_whitespace(self)
}
Expand All @@ -877,6 +891,7 @@ impl str {
#[unstable(feature = "str_words",
reason = "the precise algorithm to use is unclear")]
#[allow(deprecated)]
#[inline]
pub fn words(&self) -> Words {
UnicodeStr::words(self)
}
Expand All @@ -903,6 +918,7 @@ impl str {
/// assert_eq!(v, ["foo", "bar", "", "baz"]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn lines(&self) -> Lines {
core_str::StrExt::lines(self)
}
Expand Down Expand Up @@ -930,6 +946,7 @@ impl str {
/// assert_eq!(v, ["foo", "bar", "", "baz"]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn lines_any(&self) -> LinesAny {
core_str::StrExt::lines_any(self)
}
Expand Down

0 comments on commit 3a12b4c

Please sign in to comment.