]> git.lizzy.rs Git - rust.git/commitdiff
vec: remove each_const
authorDaniel Micay <danielmicay@gmail.com>
Mon, 17 Jun 2013 20:32:06 +0000 (16:32 -0400)
committerDaniel Micay <danielmicay@gmail.com>
Fri, 21 Jun 2013 07:20:22 +0000 (03:20 -0400)
An Iterator implementation can be made for &const [T] if it turns out
to be necessary for some use case.

src/libextra/sha1.rs
src/libstd/vec.rs

index 7c4b3f4ce39f7345ddaa9ed49912cc20d14854c9..78c4f5f13ec803e90f8a495708bbca11b39046f1 100644 (file)
@@ -36,7 +36,7 @@
 /// The SHA-1 interface
 trait Sha1 {
     /// Provide message input as bytes
-    fn input(&mut self, &const [u8]);
+    fn input(&mut self, &[u8]);
     /// Provide message input as string
     fn input_str(&mut self, &str);
     /**
@@ -74,9 +74,9 @@ struct Sha1State
           computed: bool,
           work_buf: @mut ~[u32]};
 
-    fn add_input(st: &mut Sha1State, msg: &const [u8]) {
+    fn add_input(st: &mut Sha1State, msg: &[u8]) {
         assert!((!st.computed));
-        for vec::each_const(msg) |element| {
+        for msg.iter().advance |element| {
             st.msg_block[st.msg_block_idx] = *element;
             st.msg_block_idx += 1u;
             st.len_low += 8u32;
@@ -242,7 +242,7 @@ fn reset(&mut self) {
             self.h[4] = 0xC3D2E1F0u32;
             self.computed = false;
         }
-        fn input(&mut self, msg: &const [u8]) { add_input(self, msg); }
+        fn input(&mut self, msg: &[u8]) { add_input(self, msg); }
         fn input_str(&mut self, msg: &str) {
             add_input(self, msg.as_bytes());
         }
index 7f683d0070fb3a38d68eb10ae6709b56da2799ad..1131abfafa8792dc0e7260cab0ac5ad05eab2939 100644 (file)
@@ -1427,21 +1427,6 @@ pub fn each<'r,T>(v: &'r [T], f: &fn(&'r T) -> bool) -> bool {
     return !broke;
 }
 
-/// Like `each()`, but for the case where you have a vector that *may or may
-/// not* have mutable contents.
-#[inline]
-pub fn each_const<T>(v: &const [T], f: &fn(elem: &const T) -> bool) -> bool {
-    let mut i = 0;
-    let n = v.len();
-    while i < n {
-        if !f(&const v[i]) {
-            return false;
-        }
-        i += 1;
-    }
-    return true;
-}
-
 /**
  * Iterates over a vector's elements and indices
  *