Skip to content

Commit 3a12b4c

Browse files
committed
libcollections: Inline some performance-critical string functions; e.g.
`chars()`. This was showing up in Servo profiles.
1 parent ba9224f commit 3a12b4c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/libcollections/str.rs

+17
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ impl str {
425425
since = "1.0.0")]
426426
#[unstable(feature = "unicode",
427427
reason = "this functionality may only be provided by libunicode")]
428+
#[inline]
428429
pub fn width(&self, is_cjk: bool) -> usize {
429430
UnicodeStr::width(self, is_cjk)
430431
}
@@ -459,6 +460,7 @@ impl str {
459460
with the existence of the char_indices iterator or \
460461
this method may want to be replaced with checked \
461462
slicing")]
463+
#[inline]
462464
pub fn is_char_boundary(&self, index: usize) -> bool {
463465
core_str::StrExt::is_char_boundary(self, index)
464466
}
@@ -514,6 +516,7 @@ impl str {
514516
/// }
515517
/// ```
516518
#[stable(feature = "rust1", since = "1.0.0")]
519+
#[inline]
517520
pub unsafe fn slice_unchecked(&self, begin: usize, end: usize) -> &str {
518521
core_str::StrExt::slice_unchecked(self, begin, end)
519522
}
@@ -522,6 +525,7 @@ impl str {
522525
///
523526
/// Same as `slice_unchecked`, but works with `&mut str` instead of `&str`.
524527
#[unstable(feature = "str_slice_mut", reason = "recently added")]
528+
#[inline]
525529
pub unsafe fn slice_mut_unchecked(&mut self, begin: usize, end: usize) -> &mut str {
526530
core_str::StrExt::slice_mut_unchecked(self, begin, end)
527531
}
@@ -556,6 +560,7 @@ impl str {
556560
#[deprecated(since = "1.3.0",
557561
reason = "can be implemented with char_indices and \
558562
hasn't seen enough use to justify inclusion")]
563+
#[inline]
559564
pub fn slice_chars(&self, begin: usize, end: usize) -> &str {
560565
core_str::StrExt::slice_chars(self, begin, end)
561566
}
@@ -608,6 +613,7 @@ impl str {
608613
reason = "often replaced by char_indices, this method may \
609614
be removed in favor of just char_at() or eventually \
610615
removed altogether")]
616+
#[inline]
611617
pub fn char_range_at(&self, start: usize) -> CharRange {
612618
core_str::StrExt::char_range_at(self, start)
613619
}
@@ -665,6 +671,7 @@ impl str {
665671
reason = "often replaced by char_indices, this method may \
666672
be removed in favor of just char_at_reverse() or \
667673
eventually removed altogether")]
674+
#[inline]
668675
pub fn char_range_at_reverse(&self, start: usize) -> CharRange {
669676
core_str::StrExt::char_range_at_reverse(self, start)
670677
}
@@ -691,6 +698,7 @@ impl str {
691698
future; it is normally replaced by chars/char_indices \
692699
iterators or by getting the first char from a \
693700
subslice")]
701+
#[inline]
694702
pub fn char_at(&self, i: usize) -> char {
695703
core_str::StrExt::char_at(self, i)
696704
}
@@ -716,6 +724,7 @@ impl str {
716724
reason = "see char_at for more details, but reverse semantics \
717725
are also somewhat unclear, especially with which \
718726
cases generate panics")]
727+
#[inline]
719728
pub fn char_at_reverse(&self, i: usize) -> char {
720729
core_str::StrExt::char_at_reverse(self, i)
721730
}
@@ -749,6 +758,7 @@ impl str {
749758
reason = "awaiting conventions about shifting and slices and \
750759
may not be warranted with the existence of the chars \
751760
and/or char_indices iterators")]
761+
#[inline]
752762
pub fn slice_shift_char(&self) -> Option<(char, &str)> {
753763
core_str::StrExt::slice_shift_char(self)
754764
}
@@ -810,6 +820,7 @@ impl str {
810820
/// '\u{1f1e8}', '\u{1f1ed}', ' ', '한']);
811821
/// ```
812822
#[stable(feature = "rust1", since = "1.0.0")]
823+
#[inline]
813824
pub fn chars(&self) -> Chars {
814825
core_str::StrExt::chars(self)
815826
}
@@ -825,6 +836,7 @@ impl str {
825836
/// assert_eq!(v, b);
826837
/// ```
827838
#[stable(feature = "rust1", since = "1.0.0")]
839+
#[inline]
828840
pub fn char_indices(&self) -> CharIndices {
829841
core_str::StrExt::char_indices(self)
830842
}
@@ -839,6 +851,7 @@ impl str {
839851
/// assert_eq!(v, b"bors".to_vec());
840852
/// ```
841853
#[stable(feature = "rust1", since = "1.0.0")]
854+
#[inline]
842855
pub fn bytes(&self) -> Bytes {
843856
core_str::StrExt::bytes(self)
844857
}
@@ -855,6 +868,7 @@ impl str {
855868
/// assert_eq!(v, ["Mary", "had", "a", "little", "lamb"]);
856869
/// ```
857870
#[stable(feature = "split_whitespace", since = "1.1.0")]
871+
#[inline]
858872
pub fn split_whitespace(&self) -> SplitWhitespace {
859873
UnicodeStr::split_whitespace(self)
860874
}
@@ -877,6 +891,7 @@ impl str {
877891
#[unstable(feature = "str_words",
878892
reason = "the precise algorithm to use is unclear")]
879893
#[allow(deprecated)]
894+
#[inline]
880895
pub fn words(&self) -> Words {
881896
UnicodeStr::words(self)
882897
}
@@ -903,6 +918,7 @@ impl str {
903918
/// assert_eq!(v, ["foo", "bar", "", "baz"]);
904919
/// ```
905920
#[stable(feature = "rust1", since = "1.0.0")]
921+
#[inline]
906922
pub fn lines(&self) -> Lines {
907923
core_str::StrExt::lines(self)
908924
}
@@ -930,6 +946,7 @@ impl str {
930946
/// assert_eq!(v, ["foo", "bar", "", "baz"]);
931947
/// ```
932948
#[stable(feature = "rust1", since = "1.0.0")]
949+
#[inline]
933950
pub fn lines_any(&self) -> LinesAny {
934951
core_str::StrExt::lines_any(self)
935952
}

0 commit comments

Comments
 (0)