Skip to content

Commit 31b77ae

Browse files
committed
std: remove str::to_owned and str::raw::slice_bytes_owned
1 parent cc9666f commit 31b77ae

File tree

8 files changed

+50
-70
lines changed

8 files changed

+50
-70
lines changed

src/libextra/getopts.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ pub fn opt_default(mm: &Matches, nm: &str, def: &str) -> Option<~str> {
457457
let vals = opt_vals(mm, nm);
458458
if vals.is_empty() { return None::<~str>; }
459459
return match vals[0] { Val(ref s) => Some::<~str>((*s).clone()),
460-
_ => Some::<~str>(str::to_owned(def)) }
460+
_ => Some::<~str>(def.to_owned()) }
461461
}
462462

463463
#[deriving(Eq)]
@@ -497,10 +497,10 @@ pub mod groups {
497497
desc: &str, hint: &str) -> OptGroup {
498498
let len = short_name.len();
499499
assert!(len == 1 || len == 0);
500-
return OptGroup { short_name: str::to_owned(short_name),
501-
long_name: str::to_owned(long_name),
502-
hint: str::to_owned(hint),
503-
desc: str::to_owned(desc),
500+
return OptGroup { short_name: short_name.to_owned(),
501+
long_name: long_name.to_owned(),
502+
hint: hint.to_owned(),
503+
desc: desc.to_owned(),
504504
hasarg: Yes,
505505
occur: Req};
506506
}
@@ -510,10 +510,10 @@ pub mod groups {
510510
desc: &str, hint: &str) -> OptGroup {
511511
let len = short_name.len();
512512
assert!(len == 1 || len == 0);
513-
return OptGroup {short_name: str::to_owned(short_name),
514-
long_name: str::to_owned(long_name),
515-
hint: str::to_owned(hint),
516-
desc: str::to_owned(desc),
513+
return OptGroup {short_name: short_name.to_owned(),
514+
long_name: long_name.to_owned(),
515+
hint: hint.to_owned(),
516+
desc: desc.to_owned(),
517517
hasarg: Yes,
518518
occur: Optional};
519519
}
@@ -523,10 +523,10 @@ pub mod groups {
523523
desc: &str) -> OptGroup {
524524
let len = short_name.len();
525525
assert!(len == 1 || len == 0);
526-
return OptGroup {short_name: str::to_owned(short_name),
527-
long_name: str::to_owned(long_name),
526+
return OptGroup {short_name: short_name.to_owned(),
527+
long_name: long_name.to_owned(),
528528
hint: ~"",
529-
desc: str::to_owned(desc),
529+
desc: desc.to_owned(),
530530
hasarg: No,
531531
occur: Optional};
532532
}
@@ -536,10 +536,10 @@ pub mod groups {
536536
desc: &str, hint: &str) -> OptGroup {
537537
let len = short_name.len();
538538
assert!(len == 1 || len == 0);
539-
return OptGroup {short_name: str::to_owned(short_name),
540-
long_name: str::to_owned(long_name),
541-
hint: str::to_owned(hint),
542-
desc: str::to_owned(desc),
539+
return OptGroup {short_name: short_name.to_owned(),
540+
long_name: long_name.to_owned(),
541+
hint: hint.to_owned(),
542+
desc: desc.to_owned(),
543543
hasarg: Maybe,
544544
occur: Optional};
545545
}
@@ -552,10 +552,10 @@ pub mod groups {
552552
desc: &str, hint: &str) -> OptGroup {
553553
let len = short_name.len();
554554
assert!(len == 1 || len == 0);
555-
return OptGroup {short_name: str::to_owned(short_name),
556-
long_name: str::to_owned(long_name),
557-
hint: str::to_owned(hint),
558-
desc: str::to_owned(desc),
555+
return OptGroup {short_name: short_name.to_owned(),
556+
long_name: long_name.to_owned(),
557+
hint: hint.to_owned(),
558+
desc: desc.to_owned(),
559559
hasarg: Yes,
560560
occur: Multi};
561561
}
@@ -678,7 +678,7 @@ pub mod groups {
678678
row
679679
});
680680

681-
return str::to_owned(brief) +
681+
return brief.to_owned() +
682682
"\n\nOptions:\n" +
683683
rows.collect::<~[~str]>().connect("\n") +
684684
"\n\n";

src/libextra/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ mod tests {
10271027
10281028
fn test(s: &str, format: &str) -> bool {
10291029
match strptime(s, format) {
1030-
Ok(ref tm) => tm.strftime(format) == str::to_owned(s),
1030+
Ok(ref tm) => tm.strftime(format) == s.to_owned(),
10311031
Err(e) => fail!(e)
10321032
}
10331033
}

src/librustc/metadata/filesearch.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use std::option;
1313
use std::os;
1414
use std::result;
15-
use std::str;
1615

1716
// A module for searching for libraries
1817
// FIXME (#2658): I'm not happy how this module turned out. Should
@@ -83,7 +82,7 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
8382
@FileSearchImpl {
8483
sysroot: sysroot,
8584
addl_lib_search_paths: addl_lib_search_paths,
86-
target_triple: str::to_owned(target_triple)
85+
target_triple: target_triple.to_owned()
8786
} as @FileSearch
8887
}
8988

@@ -110,7 +109,7 @@ pub fn search<T>(filesearch: @FileSearch, pick: pick<T>) -> Option<T> {
110109

111110
pub fn relative_target_lib_path(target_triple: &str) -> Path {
112111
Path(libdir()).push_many([~"rustc",
113-
str::to_owned(target_triple),
112+
target_triple.to_owned(),
114113
libdir()])
115114
}
116115

src/librustc/metadata/loader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn libname(cx: &Context) -> (~str, ~str) {
8080
os_freebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX),
8181
};
8282

83-
(str::to_owned(dll_prefix), str::to_owned(dll_suffix))
83+
(dll_prefix.to_owned(), dll_suffix.to_owned())
8484
}
8585

8686
fn find_library_crate_aux(

src/libstd/io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ impl<T:Reader> ReaderUtil for T {
763763
fn read_lines(&self) -> ~[~str] {
764764
do vec::build |push| {
765765
for self.each_line |line| {
766-
push(str::to_owned(line));
766+
push(line.to_owned());
767767
}
768768
}
769769
}

src/libstd/str.rs

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use ptr::RawPtr;
3232
use to_str::ToStr;
3333
use uint;
3434
use vec;
35-
use vec::{OwnedVector, OwnedCopyableVector, ImmutableVector};
35+
use vec::{OwnedVector, OwnedCopyableVector, ImmutableVector, MutableVector};
3636

3737
/*
3838
Section: Conditions
@@ -120,23 +120,17 @@ pub fn from_bytes_slice<'a>(vector: &'a [u8]) -> &'a str {
120120
}
121121
}
122122

123-
/// Copy a slice into a new unique str
124-
#[inline]
125-
pub fn to_owned(s: &str) -> ~str {
126-
unsafe { raw::slice_bytes_owned(s, 0, s.len()) }
127-
}
128-
129123
impl ToStr for ~str {
130124
#[inline]
131-
fn to_str(&self) -> ~str { to_owned(*self) }
125+
fn to_str(&self) -> ~str { self.to_owned() }
132126
}
133127
impl<'self> ToStr for &'self str {
134128
#[inline]
135-
fn to_str(&self) -> ~str { to_owned(*self) }
129+
fn to_str(&self) -> ~str { self.to_owned() }
136130
}
137131
impl ToStr for @str {
138132
#[inline]
139-
fn to_str(&self) -> ~str { to_owned(*self) }
133+
fn to_str(&self) -> ~str { self.to_owned() }
140134
}
141135

142136
/**
@@ -857,33 +851,6 @@ pub mod raw {
857851
::cast::transmute(v)
858852
}
859853

860-
/**
861-
* Takes a bytewise (not UTF-8) slice from a string.
862-
*
863-
* Returns the substring from [`begin`..`end`).
864-
*
865-
* # Failure
866-
*
867-
* If begin is greater than end.
868-
* If end is greater than the length of the string.
869-
*/
870-
pub unsafe fn slice_bytes_owned(s: &str, begin: uint, end: uint) -> ~str {
871-
do s.as_imm_buf |sbuf, n| {
872-
assert!((begin <= end));
873-
assert!((end <= n));
874-
875-
let mut v = vec::with_capacity(end - begin + 1u);
876-
do v.as_imm_buf |vbuf, _vlen| {
877-
let vbuf = ::cast::transmute_mut_unsafe(vbuf);
878-
let src = ptr::offset(sbuf, begin);
879-
ptr::copy_memory(vbuf, src, end - begin);
880-
}
881-
vec::raw::set_len(&mut v, end - begin);
882-
v.push(0u8);
883-
::cast::transmute(v)
884-
}
885-
}
886-
887854
/**
888855
* Takes a bytewise (not UTF-8) slice from a string.
889856
*
@@ -936,7 +903,7 @@ pub mod raw {
936903
let len = s.len();
937904
assert!((len > 0u));
938905
let b = s[0];
939-
*s = raw::slice_bytes_owned(*s, 1u, len);
906+
*s = s.slice(1, len).to_owned();
940907
return b;
941908
}
942909

@@ -1609,7 +1576,21 @@ impl<'self> StrSlice<'self> for &'self str {
16091576
16101577
/// Copy a slice into a new unique str
16111578
#[inline]
1612-
fn to_owned(&self) -> ~str { to_owned(*self) }
1579+
fn to_owned(&self) -> ~str {
1580+
do self.as_imm_buf |src, len| {
1581+
assert!(len > 0);
1582+
unsafe {
1583+
let mut v = vec::with_capacity(len);
1584+
1585+
do v.as_mut_buf |dst, _| {
1586+
ptr::copy_memory(dst, src, len - 1);
1587+
}
1588+
vec::raw::set_len(&mut v, len - 1);
1589+
v.push(0u8);
1590+
::cast::transmute(v)
1591+
}
1592+
}
1593+
}
16131594
16141595
#[inline]
16151596
fn to_managed(&self) -> @str {
@@ -2177,7 +2158,7 @@ impl OwnedStr for ~str {
21772158
*/
21782159
fn shift_char(&mut self) -> char {
21792160
let CharRange {ch, next} = self.char_range_at(0u);
2180-
*self = unsafe { raw::slice_bytes_owned(*self, next, self.len()) };
2161+
*self = self.slice(next, self.len()).to_owned();
21812162
return ch;
21822163
}
21832164
@@ -2270,7 +2251,7 @@ impl OwnedStr for ~str {
22702251
impl Clone for ~str {
22712252
#[inline]
22722253
fn clone(&self) -> ~str {
2273-
to_owned(*self)
2254+
self.to_owned()
22742255
}
22752256
}
22762257

src/test/run-pass/struct-order-of-eval-1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ struct S { f0: ~str, f1: int }
1414

1515
pub fn main() {
1616
let s = ~"Hello, world!";
17-
let _s = S { f0: str::to_owned(s), ..S { f0: s, f1: 23 } };
17+
let _s = S { f0: s.to_owned(), ..S { f0: s, f1: 23 } };
1818
}

src/test/run-pass/struct-order-of-eval-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ struct S { f0: ~str, f1: ~str }
1414

1515
pub fn main() {
1616
let s = ~"Hello, world!";
17-
let _s = S { f1: str::to_owned(s), f0: s };
17+
let _s = S { f1: s.to_owned(), f0: s };
1818
}

0 commit comments

Comments
 (0)