Skip to content

Commit

Permalink
SymbolMap implementation for object properties
Browse files Browse the repository at this point in the history
  • Loading branch information
jchlapinski committed Aug 15, 2020
1 parent f328ec3 commit ef4f0c3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Expand Up @@ -15,7 +15,7 @@ use std::path::{Path, PathBuf};
use heapsize::HeapSizeOf;
use kg_diag::io::fs;
use kg_diag::*;
use kg_symbol::Symbol;
use kg_symbol::{Symbol, SymbolMap};
use kg_utils::collections::LinkedHashMap;

pub use tree::convert::Primitive;
Expand All @@ -26,7 +26,7 @@ pub use tree::{NodeRef, TreeErrorDetail};

mod tree;

pub type Properties = LinkedHashMap<Symbol, NodeRef>;
pub type Properties = SymbolMap<NodeRef>;
pub type Elements = Vec<NodeRef>;

pub mod diff;
Expand Down
4 changes: 2 additions & 2 deletions src/opath/expr/func.rs
Expand Up @@ -578,7 +578,7 @@ pub(super) fn apply_func_to(
out.add(NodeRef::object(Properties::new()));
} else if args.count() == 1 {
let values = args.resolve_column(false, 0, env)?;
let mut map = LinkedHashMap::with_capacity(values.len());
let mut map = Properties::with_capacity(values.len());
for value in values.into_iter() {
if let Value::Object(ref props) = value.data().value() {
for (k, v) in props.iter() {
Expand All @@ -591,7 +591,7 @@ pub(super) fn apply_func_to(
args.check_count_func(id, 2, 2)?;
let keys = args.resolve_column(false, 0, env)?;
let values = args.resolve_column(true, 1, env)?;
let mut map = LinkedHashMap::with_capacity(std::cmp::min(keys.len(), values.len()));
let mut map = Properties::with_capacity(std::cmp::min(keys.len(), values.len()));
for (k, v) in keys.into_iter().zip(values.into_iter()) {
map.insert(k.as_string().to_string().into(), v);
}
Expand Down
2 changes: 1 addition & 1 deletion src/serial/de.rs
Expand Up @@ -498,7 +498,7 @@ impl<'a, 'de> serde::de::SeqAccess<'de> for Array<'a> {
}

struct Object<'a> {
iter: kg_utils::collections::linked_hash_map::Iter<'a, Symbol, NodeRef>,
iter: kg_symbol::Iter<'a, NodeRef>,
value: Option<&'a NodeRef>,
}

Expand Down
10 changes: 5 additions & 5 deletions src/serial/fmt/toml.rs
Expand Up @@ -798,7 +798,7 @@ impl Parser {

pub fn parse(&mut self, r: &mut dyn CharReader) -> Result<NodeRef, Error> {
self.token_queue.clear();
let mut root = NodeRef::object(LinkedHashMap::new());
let mut root = NodeRef::object(Properties::new());
self.parse_inner(r, &mut root)?;
Ok(root)
}
Expand Down Expand Up @@ -926,7 +926,7 @@ impl Parser {
);
}
} else {
let new = NodeRef::object(LinkedHashMap::new()).with_span(token.span());
let new = NodeRef::object(Properties::new()).with_span(token.span());
current
.add_child(None, Some(key.into()), new.clone())
.unwrap();
Expand Down Expand Up @@ -1041,7 +1041,7 @@ impl Parser {
if let Some(existing) = node.get_child_key(&key) {
return Ok(existing);
} else {
let table = NodeRef::object(LinkedHashMap::new()).with_span(Span::with_pos(from, to));
let table = NodeRef::object(Properties::new()).with_span(Span::with_pos(from, to));
node.add_child(None, Some(key.into()), table.clone())
.unwrap();
Ok(table)
Expand All @@ -1051,7 +1051,7 @@ impl Parser {
fn parse_inline_table(&mut self, r: &mut dyn CharReader) -> Result<NodeRef, Error> {
let from = self.expect_token(r, Terminal::BraceLeft)?.from();

let mut table = NodeRef::object(LinkedHashMap::new());
let mut table = NodeRef::object(Properties::new());
loop {
let (mut node, key) = self.parse_key(r, &mut table)?;
self.expect_token(r, Terminal::Equals)?;
Expand Down Expand Up @@ -1092,7 +1092,7 @@ impl Parser {
self.expect_token(r, Terminal::BracketRight)?;
let to = self.expect_token(r, Terminal::BracketRight)?.to();

let table = NodeRef::object(LinkedHashMap::new()).with_span(Span::with_pos(from, to));
let table = NodeRef::object(Properties::new()).with_span(Span::with_pos(from, to));

if node.is_array() {
if self.is_static_array(&node) {
Expand Down
3 changes: 2 additions & 1 deletion tests/tests/opath/expr/func.rs
Expand Up @@ -2,13 +2,14 @@ use super::*;
use kg_diag::Diag;
use kg_tree::opath::FuncCallErrorDetail;
use kg_tree::opath::NodeSet;

macro_rules! eval_opath {
($opath:expr) => {{
let opath = match kg_tree::opath::Opath::parse($opath) {
Ok(op) => op,
Err(err) => panic!("Error parsing opath!: {}", err),
};
let root = NodeRef::object(kg_utils::collections::LinkedHashMap::new());
let root = NodeRef::object(Properties::new());

opath.apply(&root, &root)
}};
Expand Down

0 comments on commit ef4f0c3

Please sign in to comment.