about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorErick Tryzelaar <erick.tryzelaar@gmail.com>2013-07-23 06:49:17 -0700
committerErick Tryzelaar <erick.tryzelaar@gmail.com>2013-07-23 16:56:23 -0700
commit31b77aecfc195c774852965329b5e75453eee0b2 (patch)
treebf46d091c4150e3da7c813ab4a5df633d68a08df /src
parentcc9666f68f829c17ff3a535f714fe5dbb3f72755 (diff)
downloadrust-31b77aecfc195c774852965329b5e75453eee0b2.tar.gz
rust-31b77aecfc195c774852965329b5e75453eee0b2.zip
std: remove str::to_owned and str::raw::slice_bytes_owned
Diffstat (limited to 'src')
-rw-r--r--src/libextra/getopts.rs42
-rw-r--r--src/libextra/time.rs2
-rw-r--r--src/librustc/metadata/filesearch.rs5
-rw-r--r--src/librustc/metadata/loader.rs2
-rw-r--r--src/libstd/io.rs2
-rw-r--r--src/libstd/str.rs63
-rw-r--r--src/test/run-pass/struct-order-of-eval-1.rs2
-rw-r--r--src/test/run-pass/struct-order-of-eval-2.rs2
8 files changed, 50 insertions, 70 deletions
diff --git a/src/libextra/getopts.rs b/src/libextra/getopts.rs
index 07a1c674404..c6db3637eed 100644
--- a/src/libextra/getopts.rs
+++ b/src/libextra/getopts.rs
@@ -457,7 +457,7 @@ pub fn opt_default(mm: &Matches, nm: &str, def: &str) -> Option<~str> {
     let vals = opt_vals(mm, nm);
     if vals.is_empty() { return None::<~str>; }
     return match vals[0] { Val(ref s) => Some::<~str>((*s).clone()),
-                           _      => Some::<~str>(str::to_owned(def)) }
+                           _      => Some::<~str>(def.to_owned()) }
 }
 
 #[deriving(Eq)]
@@ -497,10 +497,10 @@ pub mod groups {
                   desc: &str, hint: &str) -> OptGroup {
         let len = short_name.len();
         assert!(len == 1 || len == 0);
-        return OptGroup { short_name: str::to_owned(short_name),
-                long_name: str::to_owned(long_name),
-                hint: str::to_owned(hint),
-                desc: str::to_owned(desc),
+        return OptGroup { short_name: short_name.to_owned(),
+                long_name: long_name.to_owned(),
+                hint: hint.to_owned(),
+                desc: desc.to_owned(),
                 hasarg: Yes,
                 occur: Req};
     }
@@ -510,10 +510,10 @@ pub mod groups {
                   desc: &str, hint: &str) -> OptGroup {
         let len = short_name.len();
         assert!(len == 1 || len == 0);
-        return OptGroup {short_name: str::to_owned(short_name),
-                long_name: str::to_owned(long_name),
-                hint: str::to_owned(hint),
-                desc: str::to_owned(desc),
+        return OptGroup {short_name: short_name.to_owned(),
+                long_name: long_name.to_owned(),
+                hint: hint.to_owned(),
+                desc: desc.to_owned(),
                 hasarg: Yes,
                 occur: Optional};
     }
@@ -523,10 +523,10 @@ pub mod groups {
                    desc: &str) -> OptGroup {
         let len = short_name.len();
         assert!(len == 1 || len == 0);
-        return OptGroup {short_name: str::to_owned(short_name),
-                long_name: str::to_owned(long_name),
+        return OptGroup {short_name: short_name.to_owned(),
+                long_name: long_name.to_owned(),
                 hint: ~"",
-                desc: str::to_owned(desc),
+                desc: desc.to_owned(),
                 hasarg: No,
                 occur: Optional};
     }
@@ -536,10 +536,10 @@ pub mod groups {
                       desc: &str, hint: &str) -> OptGroup {
         let len = short_name.len();
         assert!(len == 1 || len == 0);
-        return OptGroup {short_name: str::to_owned(short_name),
-                long_name: str::to_owned(long_name),
-                hint: str::to_owned(hint),
-                desc: str::to_owned(desc),
+        return OptGroup {short_name: short_name.to_owned(),
+                long_name: long_name.to_owned(),
+                hint: hint.to_owned(),
+                desc: desc.to_owned(),
                 hasarg: Maybe,
                 occur: Optional};
     }
@@ -552,10 +552,10 @@ pub mod groups {
                     desc: &str, hint: &str) -> OptGroup {
         let len = short_name.len();
         assert!(len == 1 || len == 0);
-        return OptGroup {short_name: str::to_owned(short_name),
-                long_name: str::to_owned(long_name),
-                hint: str::to_owned(hint),
-                desc: str::to_owned(desc),
+        return OptGroup {short_name: short_name.to_owned(),
+                long_name: long_name.to_owned(),
+                hint: hint.to_owned(),
+                desc: desc.to_owned(),
                 hasarg: Yes,
                 occur: Multi};
     }
@@ -678,7 +678,7 @@ pub mod groups {
             row
         });
 
-        return str::to_owned(brief) +
+        return brief.to_owned() +
                "\n\nOptions:\n" +
                rows.collect::<~[~str]>().connect("\n") +
                "\n\n";
diff --git a/src/libextra/time.rs b/src/libextra/time.rs
index e08327f82c7..b1c07e83f52 100644
--- a/src/libextra/time.rs
+++ b/src/libextra/time.rs
@@ -1027,7 +1027,7 @@ mod tests {
 
         fn test(s: &str, format: &str) -> bool {
             match strptime(s, format) {
-              Ok(ref tm) => tm.strftime(format) == str::to_owned(s),
+              Ok(ref tm) => tm.strftime(format) == s.to_owned(),
               Err(e) => fail!(e)
             }
         }
diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs
index de4eb5c3953..6017b804b57 100644
--- a/src/librustc/metadata/filesearch.rs
+++ b/src/librustc/metadata/filesearch.rs
@@ -12,7 +12,6 @@
 use std::option;
 use std::os;
 use std::result;
-use std::str;
 
 // A module for searching for libraries
 // FIXME (#2658): I'm not happy how this module turned out. Should
@@ -83,7 +82,7 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
     @FileSearchImpl {
         sysroot: sysroot,
         addl_lib_search_paths: addl_lib_search_paths,
-        target_triple: str::to_owned(target_triple)
+        target_triple: target_triple.to_owned()
     } as @FileSearch
 }
 
@@ -110,7 +109,7 @@ pub fn search<T>(filesearch: @FileSearch, pick: pick<T>) -> Option<T> {
 
 pub fn relative_target_lib_path(target_triple: &str) -> Path {
     Path(libdir()).push_many([~"rustc",
-                              str::to_owned(target_triple),
+                              target_triple.to_owned(),
                               libdir()])
 }
 
diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs
index a0789b3e323..481d27f6944 100644
--- a/src/librustc/metadata/loader.rs
+++ b/src/librustc/metadata/loader.rs
@@ -80,7 +80,7 @@ fn libname(cx: &Context) -> (~str, ~str) {
         os_freebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX),
     };
 
-    (str::to_owned(dll_prefix), str::to_owned(dll_suffix))
+    (dll_prefix.to_owned(), dll_suffix.to_owned())
 }
 
 fn find_library_crate_aux(
diff --git a/src/libstd/io.rs b/src/libstd/io.rs
index fed4eb26dbe..05a5184ccba 100644
--- a/src/libstd/io.rs
+++ b/src/libstd/io.rs
@@ -763,7 +763,7 @@ impl<T:Reader> ReaderUtil for T {
     fn read_lines(&self) -> ~[~str] {
         do vec::build |push| {
             for self.each_line |line| {
-                push(str::to_owned(line));
+                push(line.to_owned());
             }
         }
     }
diff --git a/src/libstd/str.rs b/src/libstd/str.rs
index 59121d6f135..42b651a8e38 100644
--- a/src/libstd/str.rs
+++ b/src/libstd/str.rs
@@ -32,7 +32,7 @@ use ptr::RawPtr;
 use to_str::ToStr;
 use uint;
 use vec;
-use vec::{OwnedVector, OwnedCopyableVector, ImmutableVector};
+use vec::{OwnedVector, OwnedCopyableVector, ImmutableVector, MutableVector};
 
 /*
 Section: Conditions
@@ -120,23 +120,17 @@ pub fn from_bytes_slice<'a>(vector: &'a [u8]) -> &'a str {
     }
 }
 
-/// Copy a slice into a new unique str
-#[inline]
-pub fn to_owned(s: &str) -> ~str {
-    unsafe { raw::slice_bytes_owned(s, 0, s.len()) }
-}
-
 impl ToStr for ~str {
     #[inline]
-    fn to_str(&self) -> ~str { to_owned(*self) }
+    fn to_str(&self) -> ~str { self.to_owned() }
 }
 impl<'self> ToStr for &'self str {
     #[inline]
-    fn to_str(&self) -> ~str { to_owned(*self) }
+    fn to_str(&self) -> ~str { self.to_owned() }
 }
 impl ToStr for @str {
     #[inline]
-    fn to_str(&self) -> ~str { to_owned(*self) }
+    fn to_str(&self) -> ~str { self.to_owned() }
 }
 
 /**
@@ -867,33 +861,6 @@ pub mod raw {
      * If begin is greater than end.
      * If end is greater than the length of the string.
      */
-    pub unsafe fn slice_bytes_owned(s: &str, begin: uint, end: uint) -> ~str {
-        do s.as_imm_buf |sbuf, n| {
-            assert!((begin <= end));
-            assert!((end <= n));
-
-            let mut v = vec::with_capacity(end - begin + 1u);
-            do v.as_imm_buf |vbuf, _vlen| {
-                let vbuf = ::cast::transmute_mut_unsafe(vbuf);
-                let src = ptr::offset(sbuf, begin);
-                ptr::copy_memory(vbuf, src, end - begin);
-            }
-            vec::raw::set_len(&mut v, end - begin);
-            v.push(0u8);
-            ::cast::transmute(v)
-        }
-    }
-
-    /**
-     * Takes a bytewise (not UTF-8) slice from a string.
-     *
-     * Returns the substring from [`begin`..`end`).
-     *
-     * # Failure
-     *
-     * If begin is greater than end.
-     * If end is greater than the length of the string.
-     */
     #[inline]
     pub unsafe fn slice_bytes(s: &str, begin: uint, end: uint) -> &str {
         do s.as_imm_buf |sbuf, n| {
@@ -936,7 +903,7 @@ pub mod raw {
         let len = s.len();
         assert!((len > 0u));
         let b = s[0];
-        *s = raw::slice_bytes_owned(*s, 1u, len);
+        *s = s.slice(1, len).to_owned();
         return b;
     }
 
@@ -1609,7 +1576,21 @@ impl<'self> StrSlice<'self> for &'self str {
 
     /// Copy a slice into a new unique str
     #[inline]
-    fn to_owned(&self) -> ~str { to_owned(*self) }
+    fn to_owned(&self) -> ~str {
+        do self.as_imm_buf |src, len| {
+            assert!(len > 0);
+            unsafe {
+                let mut v = vec::with_capacity(len);
+
+                do v.as_mut_buf |dst, _| {
+                    ptr::copy_memory(dst, src, len - 1);
+                }
+                vec::raw::set_len(&mut v, len - 1);
+                v.push(0u8);
+                ::cast::transmute(v)
+            }
+        }
+    }
 
     #[inline]
     fn to_managed(&self) -> @str {
@@ -2177,7 +2158,7 @@ impl OwnedStr for ~str {
      */
     fn shift_char(&mut self) -> char {
         let CharRange {ch, next} = self.char_range_at(0u);
-        *self = unsafe { raw::slice_bytes_owned(*self, next, self.len()) };
+        *self = self.slice(next, self.len()).to_owned();
         return ch;
     }
 
@@ -2270,7 +2251,7 @@ impl OwnedStr for ~str {
 impl Clone for ~str {
     #[inline]
     fn clone(&self) -> ~str {
-        to_owned(*self)
+        self.to_owned()
     }
 }
 
diff --git a/src/test/run-pass/struct-order-of-eval-1.rs b/src/test/run-pass/struct-order-of-eval-1.rs
index cfa0401e5b9..42908a339d2 100644
--- a/src/test/run-pass/struct-order-of-eval-1.rs
+++ b/src/test/run-pass/struct-order-of-eval-1.rs
@@ -14,5 +14,5 @@ struct S { f0: ~str, f1: int }
 
 pub fn main() {
     let s = ~"Hello, world!";
-    let _s = S { f0: str::to_owned(s), ..S { f0: s, f1: 23 } };
+    let _s = S { f0: s.to_owned(), ..S { f0: s, f1: 23 } };
 }
diff --git a/src/test/run-pass/struct-order-of-eval-2.rs b/src/test/run-pass/struct-order-of-eval-2.rs
index f58e5bab3fe..b6851a72888 100644
--- a/src/test/run-pass/struct-order-of-eval-2.rs
+++ b/src/test/run-pass/struct-order-of-eval-2.rs
@@ -14,5 +14,5 @@ struct S { f0: ~str, f1: ~str }
 
 pub fn main() {
     let s = ~"Hello, world!";
-    let _s = S { f1: str::to_owned(s), f0: s };
+    let _s = S { f1: s.to_owned(), f0: s };
 }