Skip to content

Commit d9746f2

Browse files
authored
chore: reduce clones (#6903)
1 parent e55a0a3 commit d9746f2

5 files changed

Lines changed: 20 additions & 22 deletions

File tree

src/db/parity_db.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::libp2p_bitswap::{BitswapStoreRead, BitswapStoreReadWrite};
1111
use crate::rpc::eth::types::EthHash;
1212
use crate::utils::{broadcast::has_subscribers, multihash::prelude::*};
1313
use anyhow::Context as _;
14+
use bytes::Bytes;
1415
use cid::Cid;
1516
use fvm_ipld_blockstore::Blockstore;
1617
use fvm_ipld_encoding::DAG_CBOR;
@@ -83,7 +84,7 @@ impl DbColumn {
8384
}
8485
}
8586

86-
type WriteOpsBroadcastTxSender = tokio::sync::broadcast::Sender<Vec<(Cid, bytes::Bytes)>>;
87+
type WriteOpsBroadcastTxSender = tokio::sync::broadcast::Sender<Vec<(Cid, Bytes)>>;
8788

8889
pub struct ParityDb {
8990
pub db: parity_db::Db,
@@ -242,7 +243,7 @@ impl Blockstore for ParityDb {
242243
self.write_to_column(k.to_bytes(), block, column)?;
243244
match &*self.write_ops_broadcast_tx.read() {
244245
Some(tx) if has_subscribers(tx) => {
245-
let _ = tx.send(vec![(*k, bytes::Bytes::copy_from_slice(block))]);
246+
let _ = tx.send(vec![(*k, Bytes::copy_from_slice(block))]);
246247
}
247248
_ => {}
248249
}
@@ -263,7 +264,7 @@ impl Blockstore for ParityDb {
263264
let column = Self::choose_column(&k);
264265
let v = v.as_ref().to_vec();
265266
if has_subscribers {
266-
values_for_subscriber.push((k, bytes::Bytes::copy_from_slice(&v)));
267+
values_for_subscriber.push((k, Bytes::copy_from_slice(&v)));
267268
}
268269
(column, k.to_bytes(), v)
269270
});
@@ -372,7 +373,7 @@ impl ParityDb {
372373
}
373374

374375
impl super::BlockstoreWriteOpsSubscribable for ParityDb {
375-
fn subscribe_write_ops(&self) -> tokio::sync::broadcast::Receiver<Vec<(Cid, bytes::Bytes)>> {
376+
fn subscribe_write_ops(&self) -> tokio::sync::broadcast::Receiver<Vec<(Cid, Bytes)>> {
376377
let tx_lock = self.write_ops_broadcast_tx.read();
377378
if let Some(tx) = &*tx_lock {
378379
return tx.subscribe();
@@ -557,7 +558,7 @@ mod test {
557558
for (idx, cid) in cids.iter().enumerate() {
558559
let data_entry = &data[idx];
559560
db.put_keyed(cid, data_entry).unwrap();
560-
let expected = vec![(*cid, bytes::Bytes::copy_from_slice(data_entry))];
561+
let expected = vec![(*cid, Bytes::copy_from_slice(data_entry))];
561562
assert_eq!(rx1.blocking_recv().unwrap(), expected);
562563
assert_eq!(rx2.blocking_recv().unwrap(), expected);
563564
}

src/libp2p_bitswap/internals/codec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl request_response::Codec for BitswapRequestResponseCodec {
5656
let cid = prefix.to_cid(&payload.data).map_err(io::Error::other)?;
5757
parts.push(BitswapMessage::Response(
5858
cid,
59-
BitswapResponse::Block(payload.data.to_vec()),
59+
BitswapResponse::Block(payload.data),
6060
));
6161
}
6262

src/rpc/methods/eth/filter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ impl EthEventHandler {
338338
}
339339
};
340340

341-
let entries: Vec<crate::shim::executor::Entry> = event.event().entries();
341+
let entries: Vec<crate::shim::executor::Entry> = event.entries();
342342
let matched = if let Some(spec) = spec {
343343
spec.matches(&resolved, &entries)?
344344
} else {

src/rpc/types/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,9 @@ lotus_json_with_self!(Event);
546546

547547
impl From<StampedEvent> for Event {
548548
fn from(stamped: StampedEvent) -> Self {
549+
let emitter = stamped.emitter();
549550
let entries = stamped
550-
.event()
551-
.entries()
551+
.into_entries()
552552
.into_iter()
553553
.map(|entry| {
554554
let (flags, key, codec, value) = entry.into_parts();
@@ -561,10 +561,7 @@ impl From<StampedEvent> for Event {
561561
})
562562
.collect();
563563

564-
Event {
565-
emitter: stamped.emitter(),
566-
entries,
567-
}
564+
Event { emitter, entries }
568565
}
569566
}
570567

src/shim/executor.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,6 @@ pub enum ActorEvent {
217217
V4(ActorEvent_v4),
218218
}
219219

220-
impl ActorEvent {
221-
pub fn entries(&self) -> Vec<Entry> {
222-
delegate_actor_event!(self => |e| e.entries.clone().into_iter().map(Into::into).collect())
223-
}
224-
}
225-
226220
/// Event with extra information stamped by the FVM.
227221
#[delegated_enum(impl_conversions)]
228222
#[derive(Clone, Debug, Serialize)]
@@ -246,9 +240,15 @@ impl StampedEvent {
246240
delegate_stamped_event!(self.emitter)
247241
}
248242

249-
/// Returns the event as emitted by the actor.
250-
pub fn event(&self) -> ActorEvent {
251-
delegate_stamped_event!(self.event.clone().into())
243+
pub fn entries(&self) -> Vec<Entry> {
244+
delegate_stamped_event!(self => |e| e.event.entries.iter().cloned().map(Into::into).collect())
245+
}
246+
247+
pub fn into_entries(self) -> Vec<Entry> {
248+
match self {
249+
StampedEvent::V3(e) => e.event.entries.into_iter().map(Into::into).collect(),
250+
StampedEvent::V4(e) => e.event.entries.into_iter().map(Into::into).collect(),
251+
}
252252
}
253253

254254
/// Loads events directly from the events AMT root CID.

0 commit comments

Comments
 (0)