diff --git a/Cargo.lock b/Cargo.lock index db3ff5619e..62df3a1332 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -117,6 +117,7 @@ dependencies = [ "maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -148,6 +149,11 @@ dependencies = [ "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "smallvec" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "typenum" version = "1.10.0" @@ -206,6 +212,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum sized-chunks 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a2a2eb3fe454976eefb479f78f9b394d34d661b647c6326a3a6e66f68bb12c26" +"checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" "checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" diff --git a/Cargo.toml b/Cargo.toml index 0a4232714b..24bcf3c518 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ log = "0.4" petgraph = { version = "0.4.5", optional = true } combine = "3.8.1" im-rc = "13.0.0" +smallvec = "0.6.9" [dev-dependencies] pretty_assertions = "0.5.1" diff --git a/cli/Cargo.lock b/cli/Cargo.lock index 11e7ec7923..537f080af2 100644 --- a/cli/Cargo.lock +++ b/cli/Cargo.lock @@ -62,6 +62,7 @@ dependencies = [ "combine 3.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "im-rc 13.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -100,6 +101,11 @@ dependencies = [ "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "smallvec" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "typenum" version = "1.10.0" @@ -131,6 +137,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum sized-chunks 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a2a2eb3fe454976eefb479f78f9b394d34d661b647c6326a3a6e66f68bb12c26" +"checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" "checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" diff --git a/src/eval.rs b/src/eval.rs index d9a4c84410..8b6bd716cd 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -7,6 +7,7 @@ use expr::Operator::*; use std::rc::Rc; use im_rc::hashmap::HashMap; use self::Evaluated::*; +use smallvec::SmallVec; pub fn eval(expr: Expr) -> Evaluated { scoped_eval(expr, &HashMap::new()) @@ -133,7 +134,7 @@ fn eval_apply(expr: Evaluated, args: Vec, vars: &Scope) -> Evaluated { } #[inline(always)] -fn eval_closure(args: Vec, arg_patterns: Vec, vars: &Scope) +fn eval_closure(args: Vec, arg_patterns: SmallVec<[Pattern; 4]>, vars: &Scope) -> Result { if arg_patterns.len() == args.len() { @@ -224,7 +225,7 @@ fn eval_operator(Evaluated(left_expr): &Evaluated, op: Operator, Evaluated(right } #[inline(always)] -fn eval_match (condition: Evaluated, branches: Vec<(Pattern, Box)>, vars: &Scope) -> Evaluated { +fn eval_match (condition: Evaluated, branches: SmallVec<[(Pattern, Box); 4]>, vars: &Scope) -> Evaluated { let Evaluated(ref evaluated_expr) = condition; for (pattern, definition) in branches { diff --git a/src/expr.rs b/src/expr.rs index dc57c77761..113c182fd3 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1,5 +1,6 @@ use std::fmt; use self::Expr::*; +use smallvec::SmallVec; #[derive(Clone, Debug, PartialEq)] pub enum Expr { @@ -17,14 +18,14 @@ pub enum Expr { Func(String, Vec), Apply(Box, Vec), Operator(Box, Operator, Box), - Closure(Vec, Box), + Closure(SmallVec<[Pattern; 4]>, Box), // Sum Types ApplyVariant(String, Option>), // Conditionals If(Box, Box, Box), - Match(Box, Vec<(Pattern, Box)>), + Match(Box, SmallVec<[(Pattern, Box); 4]>), // Error Error(Problem), diff --git a/src/lib.rs b/src/lib.rs index 6ef7923b81..97fbe0d44f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,4 +12,5 @@ extern crate dogged; extern crate im_rc; +extern crate smallvec; #[macro_use] extern crate combine; diff --git a/src/parse.rs b/src/parse.rs index 2b976d5bcf..8b53fb3d7d 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -3,6 +3,7 @@ use expr::{Expr, Pattern}; use std::char; use parse_state::{IndentablePosition}; +use smallvec::SmallVec; use combine::parser::char::{char, string, spaces, digit, hex_digit, HexDigit, alpha_num}; use combine::parser::repeat::{many, count_min_max, sep_by1, skip_many, skip_many1}; @@ -206,7 +207,7 @@ where I: Stream, string("match").skip(indented_whitespaces1(min_indent)) .with(expr_body(min_indent)).skip(indented_whitespaces1(min_indent)) .and( - many::, _>( + many::, _>( string("when").skip(indented_whitespaces1(min_indent)) .with(pattern(min_indent)).skip(indented_whitespaces1(min_indent)) .skip(string("then")).skip(indented_whitespaces1(min_indent)) diff --git a/tests/test_parse.rs b/tests/test_parse.rs index ba39b24e5a..9c90d8418b 100644 --- a/tests/test_parse.rs +++ b/tests/test_parse.rs @@ -1,4 +1,5 @@ #[macro_use] extern crate pretty_assertions; +#[macro_use] extern crate smallvec; extern crate combine; extern crate roc; @@ -234,7 +235,7 @@ mod parse_tests { #[test] fn single_operator_with_var() { assert_eq!( - // It's important that this isn't mistaken for + // It's important that this isn't mistaken for // a declaration like (x = 1) parse_standalone("x == 1"), Ok((Operator(