Skip to content

Commit

Permalink
remove indexmap crate
Browse files Browse the repository at this point in the history
  • Loading branch information
freestrings committed Jun 24, 2019
1 parent be29571 commit 28ad9c9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 17 additions & 8 deletions src/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -1167,7 +1166,8 @@ impl SelectorMut {
origin: &Value,
target: &mut Vec<&Value>,
tokens: &mut Vec<String>,
visited: &mut IndexMap<*const Value, Vec<String>>,
visited: &mut HashSet<*const Value>,
visited_order: &mut Vec<Vec<String>>,
) -> bool {
trace!("{:?}, {:?}", target, tokens);

Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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> {
Expand Down

0 comments on commit 28ad9c9

Please sign in to comment.