Skip to content
This repository was archived by the owner on Apr 20, 2020. It is now read-only.

Commit c6334b0

Browse files
committed
avoid cloning sef.data before the replace
1 parent 4774168 commit c6334b0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/redisjson.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Translate between JSON and tree of Redis objects:
44
// User-provided JSON is converted to a tree. This tree is stored transparently in Redis.
55
// It can be operated on (e.g. INCR) and serialized back to JSON.
6-
6+
use std::mem;
77
use serde_json::Value;
88
use jsonpath_lib::{JsonPathError};
99

@@ -53,10 +53,11 @@ impl RedisJSON {
5353
// Parse the string of data into serde_json::Value.
5454
let json: Value = serde_json::from_str(data)?;
5555

56-
let v = jsonpath_lib::replace_with(self.data.clone(), path, &mut |_v| {
56+
let current_data = mem::replace(&mut self.data, Value::Null);
57+
let new_data = jsonpath_lib::replace_with(current_data, path, &mut |_v| {
5758
json.clone()
5859
})?;
59-
self.data = v;
60+
self.data = new_data;
6061

6162
Ok(())
6263
}

0 commit comments

Comments
 (0)