@@ -77,6 +77,7 @@ pub fn from_bytes_slice<'a>(vector: &'a [u8]) -> &'a str {
77
77
}
78
78
79
79
/// Copy a slice into a new unique str
80
+ #[ inline( always) ]
80
81
pub fn from_slice ( s : & str ) -> ~str {
81
82
unsafe { raw:: slice_bytes_owned ( s, 0 , len ( s) ) }
82
83
}
@@ -820,6 +821,7 @@ Section: Comparing strings
820
821
/// Bytewise slice equality
821
822
#[ cfg( notest) ]
822
823
#[ lang="str_eq" ]
824
+ #[ inline]
823
825
pub fn eq_slice ( a : & str , b : & str ) -> bool {
824
826
do as_buf ( a) |ap, alen| {
825
827
do as_buf ( b) |bp, blen| {
@@ -836,6 +838,7 @@ pub fn eq_slice(a: &str, b: &str) -> bool {
836
838
}
837
839
838
840
#[ cfg( test) ]
841
+ #[ inline]
839
842
pub fn eq_slice ( a : & str , b : & str ) -> bool {
840
843
do as_buf ( a) |ap, alen| {
841
844
do as_buf ( b) |bp, blen| {
@@ -854,15 +857,18 @@ pub fn eq_slice(a: &str, b: &str) -> bool {
854
857
/// Bytewise string equality
855
858
#[ cfg( notest) ]
856
859
#[ lang="uniq_str_eq" ]
860
+ #[ inline]
857
861
pub fn eq ( a : & ~str , b : & ~str ) -> bool {
858
862
eq_slice ( * a, * b)
859
863
}
860
864
861
865
#[ cfg( test) ]
866
+ #[ inline]
862
867
pub fn eq ( a : & ~str , b : & ~str ) -> bool {
863
868
eq_slice ( * a, * b)
864
869
}
865
870
871
+ #[ inline]
866
872
fn cmp ( a : & str , b : & str ) -> Ordering {
867
873
let low = uint:: min ( a. len ( ) , b. len ( ) ) ;
868
874
@@ -879,20 +885,24 @@ fn cmp(a: &str, b: &str) -> Ordering {
879
885
880
886
#[ cfg( notest) ]
881
887
impl < ' self > TotalOrd for & ' self str {
888
+ #[ inline]
882
889
fn cmp ( & self , other : & & ' self str ) -> Ordering { cmp ( * self , * other) }
883
890
}
884
891
885
892
#[ cfg( notest) ]
886
893
impl TotalOrd for ~str {
894
+ #[ inline]
887
895
fn cmp ( & self , other : & ~str ) -> Ordering { cmp ( * self , * other) }
888
896
}
889
897
890
898
#[ cfg( notest) ]
891
899
impl TotalOrd for @str {
900
+ #[ inline]
892
901
fn cmp ( & self , other : & @str ) -> Ordering { cmp ( * self , * other) }
893
902
}
894
903
895
904
/// Bytewise slice less than
905
+ #[ inline]
896
906
fn lt ( a : & str , b : & str ) -> bool {
897
907
let ( a_len, b_len) = ( a. len ( ) , b. len ( ) ) ;
898
908
let end = uint:: min ( a_len, b_len) ;
@@ -909,16 +919,19 @@ fn lt(a: &str, b: &str) -> bool {
909
919
}
910
920
911
921
/// Bytewise less than or equal
922
+ #[ inline]
912
923
pub fn le ( a : & str , b : & str ) -> bool {
913
924
!lt ( b, a)
914
925
}
915
926
916
927
/// Bytewise greater than or equal
928
+ #[ inline]
917
929
fn ge ( a : & str , b : & str ) -> bool {
918
930
!lt ( a, b)
919
931
}
920
932
921
933
/// Bytewise greater than
934
+ #[ inline]
922
935
fn gt ( a : & str , b : & str ) -> bool {
923
936
!le ( a, b)
924
937
}
@@ -1595,6 +1608,7 @@ Section: String properties
1595
1608
*/
1596
1609
1597
1610
/// Returns true if the string has length 0
1611
+ #[ inline( always) ]
1598
1612
pub fn is_empty ( s : & str ) -> bool { len ( s) == 0 u }
1599
1613
1600
1614
/**
@@ -1616,11 +1630,13 @@ fn is_alphanumeric(s: &str) -> bool {
1616
1630
}
1617
1631
1618
1632
/// Returns the string length/size in bytes not counting the null terminator
1633
+ #[ inline( always) ]
1619
1634
pub fn len ( s : & str ) -> uint {
1620
1635
do as_buf ( s) |_p, n| { n - 1 u }
1621
1636
}
1622
1637
1623
1638
/// Returns the number of characters that a string holds
1639
+ #[ inline( always) ]
1624
1640
pub fn char_len ( s : & str ) -> uint { count_chars ( s, 0 u, len ( s) ) }
1625
1641
1626
1642
/*
@@ -1752,7 +1768,8 @@ pub fn count_chars(s: &str, start: uint, end: uint) -> uint {
1752
1768
return len;
1753
1769
}
1754
1770
1755
- /// Counts the number of bytes taken by the `n` in `s` starting from `start`.
1771
+ /// Counts the number of bytes taken by the first `n` chars in `s`
1772
+ /// starting from `start`.
1756
1773
pub fn count_bytes < ' b > ( s : & ' b str , start : uint , n : uint ) -> uint {
1757
1774
assert ! ( is_char_boundary( s, start) ) ;
1758
1775
let mut end = start, cnt = n;
@@ -1988,6 +2005,7 @@ static tag_six_b: uint = 252u;
1988
2005
* let i = str::as_bytes("Hello World") { |bytes| vec::len(bytes) };
1989
2006
* ~~~
1990
2007
*/
2008
+ #[ inline]
1991
2009
pub fn as_bytes < T > ( s : & const ~str , f : & fn ( & ~[ u8 ] ) -> T ) -> T {
1992
2010
unsafe {
1993
2011
let v: * ~[ u8 ] = cast:: transmute ( copy s) ;
@@ -2023,6 +2041,7 @@ pub fn as_bytes_slice<'a>(s: &'a str) -> &'a [u8] {
2023
2041
* let s = str::as_c_str("PATH", { |path| libc::getenv(path) });
2024
2042
* ~~~
2025
2043
*/
2044
+ #[ inline]
2026
2045
pub fn as_c_str < T > ( s : & str , f : & fn ( * libc:: c_char ) -> T ) -> T {
2027
2046
do as_buf ( s) |buf, len| {
2028
2047
// NB: len includes the trailing null.
@@ -2099,6 +2118,7 @@ pub fn subslice_offset(outer: &str, inner: &str) -> uint {
2099
2118
* * s - A string
2100
2119
* * n - The number of bytes to reserve space for
2101
2120
*/
2121
+ #[ inline( always) ]
2102
2122
pub fn reserve ( s : & mut ~str , n : uint ) {
2103
2123
unsafe {
2104
2124
let v: * mut ~[ u8 ] = cast:: transmute ( s) ;
@@ -2126,6 +2146,7 @@ pub fn reserve(s: &mut ~str, n: uint) {
2126
2146
* * s - A string
2127
2147
* * n - The number of bytes to reserve space for
2128
2148
*/
2149
+ #[ inline( always) ]
2129
2150
pub fn reserve_at_least ( s : & mut ~str , n : uint ) {
2130
2151
reserve ( s, uint:: next_power_of_two ( n + 1 u) - 1 u)
2131
2152
}
@@ -2314,6 +2335,7 @@ pub mod raw {
2314
2335
}
2315
2336
2316
2337
/// Sets the length of the string and adds the null terminator
2338
+ #[ inline]
2317
2339
pub unsafe fn set_len ( v : & mut ~str , new_len : uint ) {
2318
2340
let v: * * mut vec:: raw:: VecRepr = cast:: transmute ( v) ;
2319
2341
let repr: * mut vec:: raw:: VecRepr = * v;
@@ -2489,7 +2511,7 @@ impl<'self> StrSlice<'self> for &'self str {
2489
2511
#[inline]
2490
2512
fn is_alphanumeric(&self) -> bool { is_alphanumeric(*self) }
2491
2513
/// Returns the size in bytes not counting the null terminator
2492
- #[inline]
2514
+ #[inline(always) ]
2493
2515
fn len(&self) -> uint { len(*self) }
2494
2516
/// Returns the number of characters that a string holds
2495
2517
#[inline]
@@ -2599,10 +2621,11 @@ pub trait OwnedStr {
2599
2621
}
2600
2622
2601
2623
impl OwnedStr for ~str {
2624
+ #[inline]
2602
2625
fn push_str(&mut self, v: &str) {
2603
2626
push_str(self, v);
2604
2627
}
2605
-
2628
+ #[inline]
2606
2629
fn push_char(&mut self, c: char) {
2607
2630
push_char(self, c);
2608
2631
}
0 commit comments