diff --git a/sway-error/src/handler.rs b/sway-error/src/handler.rs index e9bd370f1ef..24d2222da1b 100644 --- a/sway-error/src/handler.rs +++ b/sway-error/src/handler.rs @@ -1,5 +1,4 @@ use crate::{error::CompileError, warning::CompileWarning}; -use std::collections::HashMap; use core::cell::RefCell; @@ -138,37 +137,10 @@ pub struct ErrorEmitted { /// Stdlib dedup in Rust assumes sorted data for efficiency, but we don't want that. /// A hash set would also mess up the order, so this is just a brute force way of doing it /// with a vector. -fn dedup_unsorted(mut data: Vec) -> Vec { - // TODO(Centril): Consider using `IndexSet` instead for readability. - use smallvec::SmallVec; - use std::collections::hash_map::{DefaultHasher, Entry}; - use std::hash::Hasher; - - let mut write_index = 0; - let mut indexes: HashMap> = HashMap::with_capacity(data.len()); - for read_index in 0..data.len() { - let hash = { - let mut hasher = DefaultHasher::new(); - data[read_index].hash(&mut hasher); - hasher.finish() - }; - let index_vec = match indexes.entry(hash) { - Entry::Occupied(oe) => { - if oe - .get() - .iter() - .any(|index| data[*index] == data[read_index]) - { - continue; - } - oe.into_mut() - } - Entry::Vacant(ve) => ve.insert(SmallVec::new()), - }; - data.swap(write_index, read_index); - index_vec.push(write_index); - write_index += 1; - } - data.truncate(write_index); +fn dedup_unsorted(mut data: Vec) -> Vec { + use std::collections::HashSet; + + let mut seen = HashSet::new(); + data.retain(|item| seen.insert(item.clone())); data }