about summary refs log tree commit diff
path: root/src/libsyntax/opt_vec.rs
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2013-03-01 19:38:39 -0500
committerNiko Matsakis <niko@alum.mit.edu>2013-03-01 19:58:17 -0500
commitca9549bdfc3dd969e9182d58038f90bbef026ded (patch)
treed66509b54f56151513e8207da875cb4e7df9ec85 /src/libsyntax/opt_vec.rs
parent50c08dbf0d0150de41fcc7f5e87a97c4ea2bd4f0 (diff)
downloadrust-ca9549bdfc3dd969e9182d58038f90bbef026ded.tar.gz
rust-ca9549bdfc3dd969e9182d58038f90bbef026ded.zip
Avoid calling to_vec() unnecessarily in parser.
Also, rename the OptVec-to-vector conversion method to
opt_vec::take_vec() and convert from a method into a fn
because I fear strange bugs.
Diffstat (limited to 'src/libsyntax/opt_vec.rs')
-rw-r--r--src/libsyntax/opt_vec.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/libsyntax/opt_vec.rs b/src/libsyntax/opt_vec.rs
index 22d69d89e81..340e2614d2e 100644
--- a/src/libsyntax/opt_vec.rs
+++ b/src/libsyntax/opt_vec.rs
@@ -31,6 +31,14 @@ pub fn with<T>(+t: T) -> OptVec<T> {
     Vec(~[t])
 }
 
+pub fn from<T>(+t: ~[T]) -> OptVec<T> {
+    if t.len() == 0 {
+        Empty
+    } else {
+        Vec(t)
+    }
+}
+
 impl<T> OptVec<T> {
     fn push(&mut self, +t: T) {
         match *self {
@@ -70,12 +78,12 @@ impl<T> OptVec<T> {
             Vec(ref v) => v.len()
         }
     }
+}
 
-    pure fn to_vec(self) -> ~[T] {
-        match self {
-            Empty => ~[],
-            Vec(v) => v
-        }
+pub fn take_vec<T>(+v: OptVec<T>) -> ~[T] {
+    match v {
+        Empty => ~[],
+        Vec(v) => v
     }
 }