Skip to content

Commit 8254333

Browse files
committed
Revert "61 regex perf (#62)"
This reverts commit a07c7b6.
1 parent c1e3221 commit 8254333

File tree

11 files changed

+134
-449
lines changed

11 files changed

+134
-449
lines changed

CHANGELOG.md

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
1-
* **`0.1.0`**
2-
* Initial implementation
3-
* **`0.1.1`**
4-
* Technical improvements
5-
* **`0.1.2`**
6-
* added a trait to obtain the result from value
7-
* added a method to get the cloned as Value
8-
* change the name of the general method*
9-
* **`0.1.4`**
10-
* add an ability to use references instead of values
11-
* fix some clippy issues
12-
* **`0.1.5`**
13-
* correct grammar for `$.[..]`
14-
* **`0.1.6`**
15-
* add logical OR and logical And to filters
16-
* fix bugs with objects in filters
17-
* add internal macros to generate path objects
18-
* **`0.2.0`**
19-
* add json path value as a result for the library
20-
* add functions (size)
21-
* change a logical operator `size` into function `size()`
22-
* **`0.2.1`**
23-
* changed the contract for length() function.
24-
* **`0.2.2`**
25-
* add ..*
26-
* **`0.2.5`**
27-
* build for tags
28-
* **`0.2.6`**
29-
* make parser mod public
30-
* **`0.3.0`**
31-
* introduce the different behaviour for empty results and non-existing result
32-
* **`0.3.2`**
33-
* make jsonpath inst cloneable.
34-
* **`0.3.3`**
35-
* fix a bug with the logical operators
36-
* **`0.3.4`**
37-
* add a result as a path
38-
* **`0.3.5`**
39-
* add `!` negation operation in filters
40-
* allow using () in filters
41-
* **`0.5`**
42-
* add config for jsonpath
43-
* add an option to add a regex cache for boosting performance
44-
* **`0.5.1`**
45-
* add double quotes for the expressions (before it was only possible to use single quotes)
46-
* add Debug on the JsonPathFinder
47-
48-
1+
- **`0.1.0`**
2+
- Initial implementation
3+
- **`0.1.1`**
4+
- Technical improvements
5+
- **`0.1.2`**
6+
- added a trait to obtain the result from value
7+
- added a method to get the cloned as Value
8+
- change the name of the general method\*
9+
- **`0.1.4`**
10+
- add an ability to use references instead of values
11+
- fix some clippy issues
12+
- **`0.1.5`**
13+
- correct grammar for `$.[..]`
14+
- **`0.1.6`**
15+
- add logical OR and logical And to filters
16+
- fix bugs with objects in filters
17+
- add internal macros to generate path objects
18+
- **`0.2.0`**
19+
- add json path value as a result for the library
20+
- add functions (size)
21+
- change a logical operator `size` into function `size()`
22+
- **`0.2.1`**
23+
- changed the contract for length() function.
24+
- **`0.2.2`**
25+
- add ..\*
26+
- **`0.2.5`**
27+
- build for tags
28+
- **`0.2.6`**
29+
- make parser mod public
30+
- **`0.3.0`**
31+
- introduce the different behaviour for empty results and non-existing result
32+
- **`0.3.2`**
33+
- make jsonpath inst cloneable.
34+
- **`0.3.3`**
35+
- fix a bug with the logical operators
36+
- **`0.3.4`**
37+
- add a result as a path
38+
- **`0.3.5`**
39+
- add `!` negation operation in filters
40+
- allow using () in filters
41+
- **`0.5`**
42+
- add config for jsonpath
43+
- add an option to add a regex cache for boosting performance
44+
- **`0.5.1`**
45+
- add double quotes for the expressions (before it was only possible to use single quotes)
46+
- add Debug on the JsonPathFinder
47+
- **`0.6`**
48+
- allow to reuse regex, that improves performance without needing an internal cache

Cargo.toml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "jsonpath-rust"
33
description = "The library provides the basic functionality to find the set of the data according to the filtering query."
4-
version = "0.5.1"
4+
version = "0.6.0"
55
authors = ["BorisZhguchev <[email protected]>"]
66
edition = "2018"
77
license-file = "LICENSE"
@@ -17,12 +17,6 @@ regex = "1"
1717
pest = "2.0"
1818
pest_derive = "2.0"
1919
thiserror = "1.0.50"
20-
lazy_static = "1.4"
21-
once_cell = "1.19.0"
2220

2321
[dev-dependencies]
24-
criterion = "0.5.1"
25-
26-
[[bench]]
27-
name = "regex_bench"
28-
harness = false
22+
lazy_static = "1.0"

README.md

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -389,50 +389,7 @@ fn test() {
389389
** If the value has been modified during the search, there is no way to find a path of a new value.
390390
It can happen if we try to find a length() of array, for in stance.**
391391

392-
## Configuration
393392

394-
The JsonPath provides a wat to configure the search by using `JsonPathConfig`.
395-
396-
```rust
397-
pub fn main() {
398-
let cfg = JsonPathConfig::new(RegexCache::Implemented(DefaultRegexCacheInst::default()));
399-
}
400-
```
401-
402-
### Regex cache
403-
The configuration provides an ability to use a regex cache to improve the [performance](https://github.com/besok/jsonpath-rust/issues/61)
404-
405-
To instantiate the cache needs to use `RegexCache` enum with the implementation of the trait `RegexCacheInst`.
406-
Default implementation `DefaultRegexCacheInst` uses `Arc<Mutex<HashMap<String,Regex>>>`.
407-
The pair of Box<Value> or Value and config can be used:
408-
```rust
409-
pub fn main(){
410-
let cfg = JsonPathConfig::new(RegexCache::Implemented(DefaultRegexCacheInst::default()));
411-
let json = Box::new(json!({
412-
"author":"abcd(Rees)",
413-
}));
414-
415-
let _v = (json, cfg).path("$.[?(@.author ~= '.*(?i)d\\(Rees\\)')]")
416-
.expect("the path is correct");
417-
418-
419-
}
420-
```
421-
or using `JsonPathFinder` :
422-
423-
```rust
424-
fn main() {
425-
let cfg = JsonPathConfig::new(RegexCache::Implemented(DefaultRegexCacheInst::default()));
426-
let finder = JsonPathFinder::from_str_with_cfg(
427-
r#"{"first":{"second":[{"active":1},{"passive":1}]}}"#,
428-
"$.first.second[?(@.active)]",
429-
cfg,
430-
).unwrap();
431-
let slice_of_data: Vec<&Value> = finder.find_slice();
432-
let js = json!({"active":1});
433-
assert_eq!(slice_of_data, vec![JsonPathValue::Slice(&js, "$.first.second[0]".to_string())]);
434-
}
435-
```
436393

437394
## The structure
438395

benches/regex_bench.rs

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/lib.rs

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@
116116

117117
use crate::parser::model::JsonPath;
118118
use crate::parser::parser::parse_json_path;
119-
use crate::path::config::JsonPathConfig;
120119
use crate::path::{json_path_instance, PathInstance};
121120
use serde_json::Value;
122121
use std::convert::TryInto;
@@ -184,12 +183,8 @@ impl FromStr for JsonPathInst {
184183
}
185184

186185
impl JsonPathInst {
187-
pub fn find_slice<'a>(
188-
&'a self,
189-
value: &'a Value,
190-
cfg: JsonPathConfig,
191-
) -> Vec<JsonPtr<'a, Value>> {
192-
json_path_instance(&self.inner, value, cfg)
186+
pub fn find_slice<'a>(&'a self, value: &'a Value) -> Vec<JsonPtr<'a, Value>> {
187+
json_path_instance(&self.inner, value)
193188
.find(JsonPathValue::from_root(value))
194189
.into_iter()
195190
.filter(|v| v.has_value())
@@ -230,27 +225,13 @@ impl JsonPathQuery for Box<Value> {
230225
}
231226
}
232227

233-
impl JsonPathQuery for (Box<Value>, JsonPathConfig) {
234-
fn path(self, query: &str) -> Result<Value, String> {
235-
let p = JsonPathInst::from_str(query)?;
236-
Ok(JsonPathFinder::new_with_cfg(self.0, Box::new(p), self.1).find())
237-
}
238-
}
239-
240228
impl JsonPathQuery for Value {
241229
fn path(self, query: &str) -> Result<Value, String> {
242230
let p = JsonPathInst::from_str(query)?;
243231
Ok(JsonPathFinder::new(Box::new(self), Box::new(p)).find())
244232
}
245233
}
246234

247-
impl JsonPathQuery for (Value, JsonPathConfig) {
248-
fn path(self, query: &str) -> Result<Value, String> {
249-
let p = JsonPathInst::from_str(query)?;
250-
Ok(JsonPathFinder::new_with_cfg(Box::new(self.0), Box::new(p), self.1).find())
251-
}
252-
}
253-
254235
/// just to create a json path value of data
255236
/// Example:
256237
/// - json_path_value(&json) = `JsonPathValue::Slice(&json)`
@@ -314,7 +295,6 @@ type JsPathStr = String;
314295
pub(crate) fn jsp_idx(prefix: &str, idx: usize) -> String {
315296
format!("{}[{}]", prefix, idx)
316297
}
317-
318298
pub(crate) fn jsp_obj(prefix: &str, key: &str) -> String {
319299
format!("{}.['{}']", prefix, key)
320300
}
@@ -358,7 +338,7 @@ impl<'a, Data: Clone + Debug + Default> JsonPathValue<'a, Data> {
358338
}
359339

360340
impl<'a, Data> JsonPathValue<'a, Data> {
361-
fn only_no_value(input: &[JsonPathValue<'a, Data>]) -> bool {
341+
fn only_no_value(input: &Vec<JsonPathValue<'a, Data>>) -> bool {
362342
!input.is_empty() && input.iter().filter(|v| v.has_value()).count() == 0
363343
}
364344
fn map_vec(data: Vec<(&'a Data, JsPathStr)>) -> Vec<JsonPathValue<'a, Data>> {
@@ -428,7 +408,6 @@ impl<'a, Data> JsonPathValue<'a, Data> {
428408
pub struct JsonPathFinder {
429409
json: Box<Value>,
430410
path: Box<JsonPathInst>,
431-
cfg: JsonPathConfig,
432411
}
433412

434413
impl Debug for JsonPathFinder {
@@ -445,20 +424,7 @@ impl Debug for JsonPathFinder {
445424
impl JsonPathFinder {
446425
/// creates a new instance of [JsonPathFinder]
447426
pub fn new(json: Box<Value>, path: Box<JsonPathInst>) -> Self {
448-
JsonPathFinder {
449-
json,
450-
path,
451-
cfg: JsonPathConfig::default(),
452-
}
453-
}
454-
455-
pub fn new_with_cfg(json: Box<Value>, path: Box<JsonPathInst>, cfg: JsonPathConfig) -> Self {
456-
JsonPathFinder { json, path, cfg }
457-
}
458-
459-
/// sets a cfg with a new one
460-
pub fn set_cfg(&mut self, cfg: JsonPathConfig) {
461-
self.cfg = cfg
427+
JsonPathFinder { json, path }
462428
}
463429

464430
/// updates a path with a new one
@@ -486,15 +452,10 @@ impl JsonPathFinder {
486452
let path = Box::new(JsonPathInst::from_str(path)?);
487453
Ok(JsonPathFinder::new(json, path))
488454
}
489-
pub fn from_str_with_cfg(json: &str, path: &str, cfg: JsonPathConfig) -> Result<Self, String> {
490-
let json = serde_json::from_str(json).map_err(|e| e.to_string())?;
491-
let path = Box::new(JsonPathInst::from_str(path)?);
492-
Ok(JsonPathFinder::new_with_cfg(json, path, cfg))
493-
}
494455

495456
/// creates an instance to find a json slice from the json
496457
pub fn instance(&self) -> PathInstance {
497-
json_path_instance(&self.path.inner, &self.json, self.cfg.clone())
458+
json_path_instance(&self.path.inner, &self.json)
498459
}
499460
/// finds a slice of data in the set json.
500461
/// The result is a vector of references to the incoming structure.
@@ -545,7 +506,6 @@ impl JsonPathFinder {
545506

546507
#[cfg(test)]
547508
mod tests {
548-
use crate::path::config::JsonPathConfig;
549509
use crate::JsonPathQuery;
550510
use crate::JsonPathValue::{NoValue, Slice};
551511
use crate::{jp_v, JsonPathFinder, JsonPathInst, JsonPathValue};
@@ -1246,7 +1206,7 @@ mod tests {
12461206
let query = JsonPathInst::from_str("$..book[?(@.author size 10)].title")
12471207
.expect("the path is correct");
12481208

1249-
let results = query.find_slice(&json, JsonPathConfig::default());
1209+
let results = query.find_slice(&json);
12501210
let v = results.first().expect("to get value");
12511211

12521212
// V can be implicitly converted to &Value
@@ -1309,7 +1269,7 @@ mod tests {
13091269
v,
13101270
vec![Slice(
13111271
&json!({"second":{"active": 1}}),
1312-
"$.['first']".to_string(),
1272+
"$.['first']".to_string()
13131273
)]
13141274
);
13151275

@@ -1323,7 +1283,7 @@ mod tests {
13231283
v,
13241284
vec![Slice(
13251285
&json!({"second":{"active": 1}}),
1326-
"$.['first']".to_string(),
1286+
"$.['first']".to_string()
13271287
)]
13281288
);
13291289

@@ -1337,7 +1297,7 @@ mod tests {
13371297
v,
13381298
vec![Slice(
13391299
&json!({"second":{"active": 1}}),
1340-
"$.['first']".to_string(),
1300+
"$.['first']".to_string()
13411301
)]
13421302
);
13431303

@@ -1351,7 +1311,7 @@ mod tests {
13511311
v,
13521312
vec![Slice(
13531313
&json!({"second":{"active": 1}}),
1354-
"$.['first']".to_string(),
1314+
"$.['first']".to_string()
13551315
)]
13561316
);
13571317
}

src/path/config.rs

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)