Skip to content

Commit

Permalink
chore: avoid clone
Browse files Browse the repository at this point in the history
  • Loading branch information
fengjiachun committed May 14, 2024
1 parent 886af5c commit 919a56f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
9 changes: 3 additions & 6 deletions src/common/meta/src/kv_backend/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,15 @@ impl<T: ErrorExt + Send + Sync> TxnService for MemoryKvBackend<T> {

let do_txn = |txn_op| match txn_op {
TxnOp::Put(key, value) => {
kvs.insert(key.clone(), value);
kvs.insert(key, value);
TxnOpResponse::ResponsePut(PutResponse { prev_kv: None })
}

TxnOp::Get(key) => {
let value = kvs.get(&key);
let value = kvs.get(&key).cloned();
let kvs = value
.map(|value| KeyValue { key, value })
.into_iter()
.map(|value| KeyValue {
key: key.clone(),
value: value.clone(),
})
.collect();
TxnOpResponse::ResponseGet(RangeResponse { kvs, more: false })
}
Expand Down
7 changes: 2 additions & 5 deletions src/log-store/src/raft_engine/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl TxnService for RaftEngineBackend {
let do_txn = |txn_op| match txn_op {
TxnOp::Put(key, value) => {
batch
.put(SYSTEM_NAMESPACE, key.clone(), value)
.put(SYSTEM_NAMESPACE, key, value)
.context(RaftEngineSnafu)
.map_err(BoxedError::new)
.context(meta_error::ExternalSnafu)?;
Expand All @@ -113,11 +113,8 @@ impl TxnService for RaftEngineBackend {
TxnOp::Get(key) => {
let value = engine_get(&engine, &key)?.map(|kv| kv.value);
let kvs = value
.map(|value| KeyValue { key, value })
.into_iter()
.map(|value| KeyValue {
key: key.clone(),
value,
})
.collect();
Ok(TxnOpResponse::ResponseGet(RangeResponse {
kvs,
Expand Down

0 comments on commit 919a56f

Please sign in to comment.