]> git.lizzy.rs Git - rust.git/commitdiff
Convert vec::{head, tail, init, last} (and similar fns) to methods.
authorHuon Wilson <dbau.pp+github@gmail.com>
Thu, 27 Jun 2013 12:36:27 +0000 (22:36 +1000)
committerHuon Wilson <dbau.pp+github@gmail.com>
Thu, 27 Jun 2013 12:37:00 +0000 (22:37 +1000)
src/compiletest/compiletest.rs
src/libextra/test.rs
src/librustc/middle/trans/cabi_x86_64.rs
src/librustc/middle/trans/callee.rs
src/librustc/middle/trans/meth.rs
src/librustc/middle/ty.rs
src/libstd/vec.rs

index e8876c4851bc71512d5bd7b73422fa8646fc413d..b2ba05c550deffa225b8cfd3adac94d47a956835 100644 (file)
@@ -75,7 +75,7 @@ pub fn parse_config(args: ~[~str]) -> config {
          ];
 
     assert!(!args.is_empty());
-    let args_ = vec::tail(args);
+    let args_ = args.tail();
     let matches =
         &match getopts::getopts(args_, opts) {
           Ok(m) => m,
index 72e70943ce1cce47662bbb2f29d6ac18165b410c..bb03e3ab9bb272ac2f9012807a0313bc77a0493b 100644 (file)
@@ -139,7 +139,7 @@ pub struct TestOpts {
 
 // Parses command line arguments into test options
 pub fn parse_opts(args: &[~str]) -> OptRes {
-    let args_ = vec::tail(args);
+    let args_ = args.tail();
     let opts = ~[getopts::optflag("ignored"),
                  getopts::optflag("test"),
                  getopts::optflag("bench"),
index 14ab17f5030d6a34ac2dcd4675d0701b143bb428..73323634c2b6c89c74f65f29d6efaf010b7ad77c 100644 (file)
@@ -312,7 +312,7 @@ fn llvec_len(cls: &[RegClass]) -> uint {
                 tys.push(Type::i64());
             }
             SSEFv => {
-                let vec_len = llvec_len(vec::tailn(cls, i + 1u)) * 2u;
+                let vec_len = llvec_len(cls.tailn(i + 1u)) * 2u;
                 let vec_ty = Type::vector(&Type::f32(), vec_len as u64);
                 tys.push(vec_ty);
                 i += vec_len;
index cb475550638433690a95e0674dc6ce04bbd618fd..064a457c712700c464121208ee6fb5355721569a 100644 (file)
@@ -47,7 +47,6 @@
 
 use middle::trans::type_::Type;
 
-use core::vec;
 use syntax::ast;
 use syntax::ast_map;
 use syntax::visit;
@@ -503,7 +502,7 @@ pub fn trans_call_inner(in_cx: block,
     do base::with_scope(in_cx, call_info, "call") |cx| {
         let ret_in_loop = match args {
           ArgExprs(args) => {
-            args.len() > 0u && match vec::last(args).node {
+            args.len() > 0u && match args.last().node {
               ast::expr_loop_body(@ast::expr {
                 node: ast::expr_fn_block(_, ref body),
                 _
index 38e4f087b0ecd980a049b4f03a89f7d4f50e827c..b6911a7eb96d5c4869e66fce8e0ad30147200c61 100644 (file)
@@ -492,8 +492,7 @@ pub fn combine_impl_and_methods_tps(bcx: block,
     debug!("rcvr_substs=%?", rcvr_substs.map(|t| bcx.ty_to_str(*t)));
     let ty_substs
         = vec::append(rcvr_substs.to_owned(),
-                      vec::tailn(node_substs,
-                                 node_substs.len() - n_m_tps));
+                      node_substs.tailn(node_substs.len() - n_m_tps));
     debug!("n_m_tps=%?", n_m_tps);
     debug!("node_substs=%?", node_substs.map(|t| bcx.ty_to_str(*t)));
     debug!("ty_substs=%?", ty_substs.map(|t| bcx.ty_to_str(*t)));
@@ -540,7 +539,7 @@ pub fn combine_impl_and_methods_origins(bcx: block,
     };
 
     // Extract those that belong to method:
-    let m_origins = vec::tailn(*r_m_origins, r_m_origins.len() - m_vtables);
+    let m_origins = r_m_origins.tailn(r_m_origins.len() - m_vtables);
 
     // Combine rcvr + method to find the final result:
     @vec::append(/*bad*/copy *rcvr_origins, m_origins)
index 4cea4c949724097ad882d1eca2237a9ddbb1cc43..939fecfe40aec207acd60a63757687d70d362e63 100644 (file)
@@ -3954,7 +3954,7 @@ pub fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path {
           }
 
           ast_map::node_variant(ref variant, _, path) => {
-            vec::append_one(vec::to_owned(vec::init(*path)),
+            vec::append_one(vec::to_owned(path.init()),
                             ast_map::path_name((*variant).node.name))
           }
 
index c8dc5aa7f79923cb8edb9549f129672abee3cbe1..3dae32d717de090bf07f68d05936eb4fde365f5d 100644 (file)
@@ -238,44 +238,6 @@ pub fn build_sized_opt<A>(size: Option<uint>,
 
 // Accessors
 
-/// Returns the first element of a vector
-pub fn head<'r,T>(v: &'r [T]) -> &'r T {
-    if v.len() == 0 { fail!("head: empty vector") }
-    &v[0]
-}
-
-/// Returns `Some(x)` where `x` is the first element of the slice `v`,
-/// or `None` if the vector is empty.
-pub fn head_opt<'r,T>(v: &'r [T]) -> Option<&'r T> {
-    if v.len() == 0 { None } else { Some(&v[0]) }
-}
-
-/// Returns a vector containing all but the first element of a slice
-pub fn tail<'r,T>(v: &'r [T]) -> &'r [T] { v.slice(1, v.len()) }
-
-/// Returns a vector containing all but the first `n` elements of a slice
-pub fn tailn<'r,T>(v: &'r [T], n: uint) -> &'r [T] { v.slice(n, v.len()) }
-
-/// Returns a vector containing all but the last element of a slice
-pub fn init<'r,T>(v: &'r [T]) -> &'r [T] { v.slice(0, v.len() - 1) }
-
-/// Returns a vector containing all but the last `n' elements of a slice
-pub fn initn<'r,T>(v: &'r [T], n: uint) -> &'r [T] {
-    v.slice(0, v.len() - n)
-}
-
-/// Returns the last element of the slice `v`, failing if the slice is empty.
-pub fn last<'r,T>(v: &'r [T]) -> &'r T {
-    if v.len() == 0 { fail!("last: empty vector") }
-    &v[v.len() - 1]
-}
-
-/// Returns `Some(x)` where `x` is the last element of the slice `v`, or
-/// `None` if the vector is empty.
-pub fn last_opt<'r,T>(v: &'r [T]) -> Option<&'r T> {
-    if v.len() == 0 { None } else { Some(&v[v.len() - 1]) }
-}
-
 /// Copies
 
 /// Split the vector `v` by applying each element against the predicate `f`.
@@ -1678,35 +1640,49 @@ fn rev_iter(self) -> VecRevIterator<'self, T> {
 
     /// Returns the first element of a vector, failing if the vector is empty.
     #[inline]
-    fn head(&self) -> &'self T { head(*self) }
+    fn head(&self) -> &'self T {
+        if self.len() == 0 { fail!("head: empty vector") }
+        &self[0]
+    }
 
-    /// Returns the first element of a vector
+    /// Returns the first element of a vector, or `None` if it is empty
     #[inline]
-    fn head_opt(&self) -> Option<&'self T> { head_opt(*self) }
+    fn head_opt(&self) -> Option<&'self T> {
+        if self.len() == 0 { None } else { Some(&self[0]) }
+    }
 
     /// Returns all but the first element of a vector
     #[inline]
-    fn tail(&self) -> &'self [T] { tail(*self) }
+    fn tail(&self) -> &'self [T] { self.slice(1, self.len()) }
 
     /// Returns all but the first `n' elements of a vector
     #[inline]
-    fn tailn(&self, n: uint) -> &'self [T] { tailn(*self, n) }
+    fn tailn(&self, n: uint) -> &'self [T] { self.slice(n, self.len()) }
 
-    /// Returns all but the last elemnt of a vector
+    /// Returns all but the last element of a vector
     #[inline]
-    fn init(&self) -> &'self [T] { init(*self) }
+    fn init(&self) -> &'self [T] {
+        self.slice(0, self.len() - 1)
+    }
 
     /// Returns all but the last `n' elemnts of a vector
     #[inline]
-    fn initn(&self, n: uint) -> &'self [T] { initn(*self, n) }
+    fn initn(&self, n: uint) -> &'self [T] {
+        self.slice(0, self.len() - n)
+    }
 
-    /// Returns the last element of a `v`, failing if the vector is empty.
+    /// Returns the last element of a vector, failing if the vector is empty.
     #[inline]
-    fn last(&self) -> &'self T { last(*self) }
+    fn last(&self) -> &'self T {
+        if self.len() == 0 { fail!("last: empty vector") }
+        &self[self.len() - 1]
+    }
 
-    /// Returns the last element of a `v`, failing if the vector is empty.
+    /// Returns the last element of a vector, or `None` if it is empty.
     #[inline]
-    fn last_opt(&self) -> Option<&'self T> { last_opt(*self) }
+    fn last_opt(&self) -> Option<&'self T> {
+            if self.len() == 0 { None } else { Some(&self[self.len() - 1]) }
+    }
 
     /**
      * Find the last index matching some predicate