From 28ad9c903f3e4542da481dc45c30256e618fe753 Mon Sep 17 00:00:00 2001 From: freestrings Date: Mon, 24 Jun 2019 14:12:00 +0900 Subject: [PATCH] remove indexmap crate --- Cargo.toml | 1 - src/lib.rs | 1 - src/select/mod.rs | 25 +++++++++++++++++-------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index afda4ad1..9a9318a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ log = "0.4" env_logger = "0.6.0" serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0", features = ["preserve_order"] } -indexmap = "1.0.2" array_tool = "~1.0.3" [dev-dependencies] diff --git a/src/lib.rs b/src/lib.rs index 57826921..78643427 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -125,7 +125,6 @@ extern crate array_tool; extern crate core; extern crate env_logger; -extern crate indexmap; #[macro_use] extern crate log; extern crate serde; diff --git a/src/select/mod.rs b/src/select/mod.rs index bb947450..7713703f 100644 --- a/src/select/mod.rs +++ b/src/select/mod.rs @@ -2,7 +2,6 @@ use std::collections::HashSet; use std::fmt; use array_tool::vec::{Intersect, Union}; -use indexmap::IndexMap; use serde_json::{Number, Value}; use parser::parser::*; @@ -1167,7 +1166,8 @@ impl SelectorMut { origin: &Value, target: &mut Vec<&Value>, tokens: &mut Vec, - visited: &mut IndexMap<*const Value, Vec>, + visited: &mut HashSet<*const Value>, + visited_order: &mut Vec>, ) -> bool { trace!("{:?}, {:?}", target, tokens); @@ -1177,7 +1177,9 @@ impl SelectorMut { target.retain(|t| { if std::ptr::eq(origin, *t) { - visited.insert(*t, tokens.to_vec()); + if visited.insert(*t) { + visited_order.push(tokens.to_vec()); + } false } else { true @@ -1188,7 +1190,7 @@ impl SelectorMut { Value::Array(vec) => { for (i, v) in vec.iter().enumerate() { tokens.push(i.to_string()); - if _walk(v, target, tokens, visited) { + if _walk(v, target, tokens, visited, visited_order) { return true; } tokens.pop(); @@ -1197,7 +1199,7 @@ impl SelectorMut { Value::Object(map) => { for (k, v) in map { tokens.push(k.clone()); - if _walk(v, target, tokens, visited) { + if _walk(v, target, tokens, visited, visited_order) { return true; } tokens.pop(); @@ -1209,14 +1211,21 @@ impl SelectorMut { return false; } - let mut visited = IndexMap::new(); + let mut visited = HashSet::new(); + let mut visited_order = Vec::new(); if let Some(origin) = &self.value { let mut tokens = Vec::new(); - _walk(origin, &mut result, &mut tokens, &mut visited); + _walk( + origin, + &mut result, + &mut tokens, + &mut visited, + &mut visited_order, + ); } - visited.iter().map(|(_, v)| v.to_vec()).collect() + visited_order } pub fn delete(&mut self) -> Result<&mut Self, JsonPathError> {