Skip to content

Commit afcb9e9

Browse files
committed
core: inlining on common functions
1 parent b4bdc3f commit afcb9e9

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/libcore/str.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub fn from_bytes_slice<'a>(vector: &'a [u8]) -> &'a str {
7777
}
7878

7979
/// Copy a slice into a new unique str
80+
#[inline(always)]
8081
pub fn from_slice(s: &str) -> ~str {
8182
unsafe { raw::slice_bytes_owned(s, 0, len(s)) }
8283
}
@@ -820,6 +821,7 @@ Section: Comparing strings
820821
/// Bytewise slice equality
821822
#[cfg(notest)]
822823
#[lang="str_eq"]
824+
#[inline]
823825
pub fn eq_slice(a: &str, b: &str) -> bool {
824826
do as_buf(a) |ap, alen| {
825827
do as_buf(b) |bp, blen| {
@@ -836,6 +838,7 @@ pub fn eq_slice(a: &str, b: &str) -> bool {
836838
}
837839

838840
#[cfg(test)]
841+
#[inline]
839842
pub fn eq_slice(a: &str, b: &str) -> bool {
840843
do as_buf(a) |ap, alen| {
841844
do as_buf(b) |bp, blen| {
@@ -854,15 +857,18 @@ pub fn eq_slice(a: &str, b: &str) -> bool {
854857
/// Bytewise string equality
855858
#[cfg(notest)]
856859
#[lang="uniq_str_eq"]
860+
#[inline]
857861
pub fn eq(a: &~str, b: &~str) -> bool {
858862
eq_slice(*a, *b)
859863
}
860864

861865
#[cfg(test)]
866+
#[inline]
862867
pub fn eq(a: &~str, b: &~str) -> bool {
863868
eq_slice(*a, *b)
864869
}
865870

871+
#[inline]
866872
fn cmp(a: &str, b: &str) -> Ordering {
867873
let low = uint::min(a.len(), b.len());
868874

@@ -879,20 +885,24 @@ fn cmp(a: &str, b: &str) -> Ordering {
879885

880886
#[cfg(notest)]
881887
impl<'self> TotalOrd for &'self str {
888+
#[inline]
882889
fn cmp(&self, other: & &'self str) -> Ordering { cmp(*self, *other) }
883890
}
884891

885892
#[cfg(notest)]
886893
impl TotalOrd for ~str {
894+
#[inline]
887895
fn cmp(&self, other: &~str) -> Ordering { cmp(*self, *other) }
888896
}
889897

890898
#[cfg(notest)]
891899
impl TotalOrd for @str {
900+
#[inline]
892901
fn cmp(&self, other: &@str) -> Ordering { cmp(*self, *other) }
893902
}
894903

895904
/// Bytewise slice less than
905+
#[inline]
896906
fn lt(a: &str, b: &str) -> bool {
897907
let (a_len, b_len) = (a.len(), b.len());
898908
let end = uint::min(a_len, b_len);
@@ -909,16 +919,19 @@ fn lt(a: &str, b: &str) -> bool {
909919
}
910920

911921
/// Bytewise less than or equal
922+
#[inline]
912923
pub fn le(a: &str, b: &str) -> bool {
913924
!lt(b, a)
914925
}
915926

916927
/// Bytewise greater than or equal
928+
#[inline]
917929
fn ge(a: &str, b: &str) -> bool {
918930
!lt(a, b)
919931
}
920932

921933
/// Bytewise greater than
934+
#[inline]
922935
fn gt(a: &str, b: &str) -> bool {
923936
!le(a, b)
924937
}
@@ -1595,6 +1608,7 @@ Section: String properties
15951608
*/
15961609

15971610
/// Returns true if the string has length 0
1611+
#[inline(always)]
15981612
pub fn is_empty(s: &str) -> bool { len(s) == 0u }
15991613

16001614
/**
@@ -1616,11 +1630,13 @@ fn is_alphanumeric(s: &str) -> bool {
16161630
}
16171631

16181632
/// Returns the string length/size in bytes not counting the null terminator
1633+
#[inline(always)]
16191634
pub fn len(s: &str) -> uint {
16201635
do as_buf(s) |_p, n| { n - 1u }
16211636
}
16221637

16231638
/// Returns the number of characters that a string holds
1639+
#[inline(always)]
16241640
pub fn char_len(s: &str) -> uint { count_chars(s, 0u, len(s)) }
16251641

16261642
/*
@@ -1752,7 +1768,8 @@ pub fn count_chars(s: &str, start: uint, end: uint) -> uint {
17521768
return len;
17531769
}
17541770

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`.
17561773
pub fn count_bytes<'b>(s: &'b str, start: uint, n: uint) -> uint {
17571774
assert!(is_char_boundary(s, start));
17581775
let mut end = start, cnt = n;
@@ -1988,6 +2005,7 @@ static tag_six_b: uint = 252u;
19882005
* let i = str::as_bytes("Hello World") { |bytes| vec::len(bytes) };
19892006
* ~~~
19902007
*/
2008+
#[inline]
19912009
pub fn as_bytes<T>(s: &const ~str, f: &fn(&~[u8]) -> T) -> T {
19922010
unsafe {
19932011
let v: *~[u8] = cast::transmute(copy s);
@@ -2023,6 +2041,7 @@ pub fn as_bytes_slice<'a>(s: &'a str) -> &'a [u8] {
20232041
* let s = str::as_c_str("PATH", { |path| libc::getenv(path) });
20242042
* ~~~
20252043
*/
2044+
#[inline]
20262045
pub fn as_c_str<T>(s: &str, f: &fn(*libc::c_char) -> T) -> T {
20272046
do as_buf(s) |buf, len| {
20282047
// NB: len includes the trailing null.
@@ -2099,6 +2118,7 @@ pub fn subslice_offset(outer: &str, inner: &str) -> uint {
20992118
* * s - A string
21002119
* * n - The number of bytes to reserve space for
21012120
*/
2121+
#[inline(always)]
21022122
pub fn reserve(s: &mut ~str, n: uint) {
21032123
unsafe {
21042124
let v: *mut ~[u8] = cast::transmute(s);
@@ -2126,6 +2146,7 @@ pub fn reserve(s: &mut ~str, n: uint) {
21262146
* * s - A string
21272147
* * n - The number of bytes to reserve space for
21282148
*/
2149+
#[inline(always)]
21292150
pub fn reserve_at_least(s: &mut ~str, n: uint) {
21302151
reserve(s, uint::next_power_of_two(n + 1u) - 1u)
21312152
}
@@ -2314,6 +2335,7 @@ pub mod raw {
23142335
}
23152336

23162337
/// Sets the length of the string and adds the null terminator
2338+
#[inline]
23172339
pub unsafe fn set_len(v: &mut ~str, new_len: uint) {
23182340
let v: **mut vec::raw::VecRepr = cast::transmute(v);
23192341
let repr: *mut vec::raw::VecRepr = *v;
@@ -2489,7 +2511,7 @@ impl<'self> StrSlice<'self> for &'self str {
24892511
#[inline]
24902512
fn is_alphanumeric(&self) -> bool { is_alphanumeric(*self) }
24912513
/// Returns the size in bytes not counting the null terminator
2492-
#[inline]
2514+
#[inline(always)]
24932515
fn len(&self) -> uint { len(*self) }
24942516
/// Returns the number of characters that a string holds
24952517
#[inline]
@@ -2599,10 +2621,11 @@ pub trait OwnedStr {
25992621
}
26002622
26012623
impl OwnedStr for ~str {
2624+
#[inline]
26022625
fn push_str(&mut self, v: &str) {
26032626
push_str(self, v);
26042627
}
2605-
2628+
#[inline]
26062629
fn push_char(&mut self, c: char) {
26072630
push_char(self, c);
26082631
}

0 commit comments

Comments
 (0)