Skip to content

Commit

Permalink
Use HashSet instead of Vec
Browse files Browse the repository at this point in the history
  • Loading branch information
cburgdorf committed Jan 21, 2021
1 parent 93ed841 commit c313633
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 5 additions & 2 deletions semantics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ use std::cell::{
Ref,
RefCell,
};
use std::collections::HashMap;
use std::collections::{
HashMap,
HashSet,
};
use std::rc::Rc;

/// Indicates where an expression is stored.
Expand Down Expand Up @@ -68,7 +71,7 @@ pub struct ContractAttributes {
/// Events that have been defined by the user.
pub events: Vec<Event>,
/// Static strings that the contract defines
pub string_literals: Vec<String>,
pub string_literals: HashSet<String>,
}

impl From<Ref<'_, ContractScope>> for ContractAttributes {
Expand Down
11 changes: 7 additions & 4 deletions semantics/src/namespace/scopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use crate::namespace::types::{
Type,
};
use std::cell::RefCell;
use std::collections::HashMap;
use std::collections::{
HashMap,
HashSet,
};
use std::rc::Rc;

pub type Shared<T> = Rc<RefCell<T>>;
Expand Down Expand Up @@ -35,7 +38,7 @@ pub struct ContractScope {
pub event_defs: HashMap<String, Event>,
pub field_defs: HashMap<String, ContractFieldDef>,
pub function_defs: HashMap<String, ContractFunctionDef>,
pub string_defs: Vec<String>,
pub string_defs: HashSet<String>,
num_fields: usize,
}

Expand Down Expand Up @@ -97,7 +100,7 @@ impl ContractScope {
function_defs: HashMap::new(),
event_defs: HashMap::new(),
field_defs: HashMap::new(),
string_defs: vec![],
string_defs: HashSet::new(),
interface: vec![],
num_fields: 0,
}))
Expand Down Expand Up @@ -159,7 +162,7 @@ impl ContractScope {

/// Add a static string definition to the scope.
pub fn add_string(&mut self, value: String) {
self.string_defs.push(value);
self.string_defs.insert(value);
}
}

Expand Down

0 comments on commit c313633

Please sign in to comment.