From 9ef8eaa4564b2e498c56cad50491f2fdcea9d643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Tue, 9 Mar 2021 17:01:53 +0100 Subject: change union to hashset from vector --- src/compiler.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/compiler.rs') diff --git a/src/compiler.rs b/src/compiler.rs index bdc5901..588a9e9 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -1,6 +1,6 @@ use std::path::{Path, PathBuf}; use std::cell::RefCell; -use std::collections::{HashMap, hash_map::Entry}; +use std::collections::{HashMap, HashSet, hash_map::Entry}; use std::rc::Rc; use crate::{Blob, Block, Op, Prog, RustFunction, Type, Value}; @@ -1403,18 +1403,19 @@ impl Compiler { } fn parse_type(&mut self) -> Result { - let mut tys = vec![self.parse_simple_type()?]; + let mut tys = HashSet::new(); + tys.insert(self.parse_simple_type()?); loop { match self.peek() { Token::Questionmark => { self.eat(); - tys.push(Type::Void); + tys.insert(Type::Void); return Ok(Type::Union(tys)); }, Token::Pipe => { self.eat(); - tys.push(self.parse_simple_type()?); + tys.insert(self.parse_simple_type()?); }, _ => { @@ -1423,7 +1424,7 @@ impl Compiler { } } if tys.len() == 1 { - Ok(tys[0].clone()) + Ok(tys.iter().next().unwrap().clone()) } else { Ok(Type::Union(tys)) } -- cgit v1.2.1