mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
chore: Clippy fixes
This commit is contained in:
@@ -1,7 +1,4 @@
|
|||||||
use std::{
|
use std::collections::HashSet;
|
||||||
cmp::Ordering,
|
|
||||||
collections::{BTreeSet, HashMap, HashSet},
|
|
||||||
};
|
|
||||||
|
|
||||||
use indexmap::IndexSet;
|
use indexmap::IndexSet;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
@@ -39,7 +36,7 @@ pub(super) struct Stitcher<'backend, B: StitcherBackend> {
|
|||||||
impl<B: StitcherBackend> Stitcher<'_, B> {
|
impl<B: StitcherBackend> Stitcher<'_, B> {
|
||||||
pub(super) fn new(backend: &B) -> Stitcher<'_, B> { Stitcher { backend } }
|
pub(super) fn new(backend: &B) -> Stitcher<'_, B> { Stitcher { backend } }
|
||||||
|
|
||||||
pub(super) fn stitch<'id>(&self, batch: Batch<'id>) -> OrderUpdates<'id, B::Key> {
|
pub(super) fn stitch<'id>(&self, batch: &Batch<'id>) -> OrderUpdates<'id, B::Key> {
|
||||||
let mut gap_updates = Vec::new();
|
let mut gap_updates = Vec::new();
|
||||||
let mut all_new_events: HashSet<&'id str> = HashSet::new();
|
let mut all_new_events: HashSet<&'id str> = HashSet::new();
|
||||||
|
|
||||||
@@ -100,9 +97,12 @@ impl<B: StitcherBackend> Stitcher<'_, B> {
|
|||||||
.sorted_by(batch.compare_by_dag_received())
|
.sorted_by(batch.compare_by_dag_received())
|
||||||
.collect_vec();
|
.collect_vec();
|
||||||
|
|
||||||
let mut items = Vec::with_capacity(
|
// allocate 1.5x the size of the to-insert list
|
||||||
events_to_insert.capacity() + events_to_insert.capacity().div_euclid(2),
|
let items_capacity = events_to_insert
|
||||||
);
|
.capacity()
|
||||||
|
.saturating_add(events_to_insert.capacity().div_euclid(2));
|
||||||
|
|
||||||
|
let mut items = Vec::with_capacity(items_capacity);
|
||||||
|
|
||||||
for event in events_to_insert {
|
for event in events_to_insert {
|
||||||
let missing_prev_events: HashSet<String> = batch
|
let missing_prev_events: HashSet<String> = batch
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
use std::{
|
use std::{cmp::Ordering, collections::HashSet};
|
||||||
cmp::Ordering,
|
|
||||||
collections::{BTreeMap, HashSet},
|
|
||||||
};
|
|
||||||
|
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
|
|
||||||
@@ -58,10 +55,10 @@ pub(super) struct Batch<'id> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'id> Batch<'id> {
|
impl<'id> Batch<'id> {
|
||||||
pub(super) fn from_edges(edges: EventEdges<'_>) -> Batch<'_> {
|
pub(super) fn from_edges<'edges>(edges: &EventEdges<'edges>) -> Batch<'edges> {
|
||||||
let mut events = IndexMap::new();
|
let mut events = IndexMap::new();
|
||||||
|
|
||||||
for (event, prev_events) in &edges {
|
for (event, prev_events) in edges {
|
||||||
let predecessor_set = Self::find_predecessor_set(event, &edges);
|
let predecessor_set = Self::find_predecessor_set(event, &edges);
|
||||||
|
|
||||||
events.insert(*event, EventPredecessors {
|
events.insert(*event, EventPredecessors {
|
||||||
|
|||||||
@@ -36,7 +36,9 @@ impl<'id> TestStitcherBackend<'id> {
|
|||||||
},
|
},
|
||||||
| None => unreachable!("we just checked that this index is valid"),
|
| None => unreachable!("we just checked that this index is valid"),
|
||||||
}
|
}
|
||||||
gap_index + 1
|
gap_index.checked_add(1).expect(
|
||||||
|
"should never allocate usize::MAX ids. what kind of test are you running",
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
let to_insert: Vec<_> = update
|
let to_insert: Vec<_> = update
|
||||||
@@ -97,8 +99,8 @@ fn run_testcase(testcase: parser::TestCase<'_>) {
|
|||||||
|
|
||||||
for (index, phase) in testcase.into_iter().enumerate() {
|
for (index, phase) in testcase.into_iter().enumerate() {
|
||||||
let stitcher = Stitcher::new(&backend);
|
let stitcher = Stitcher::new(&backend);
|
||||||
let batch = Batch::from_edges(phase.batch);
|
let batch = Batch::from_edges(&phase.batch);
|
||||||
let updates = stitcher.stitch(batch);
|
let updates = stitcher.stitch(&batch);
|
||||||
|
|
||||||
println!();
|
println!();
|
||||||
println!("===== phase {index}");
|
println!("===== phase {index}");
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use std::collections::{BTreeMap, HashSet};
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
|
|
||||||
use crate::rooms::timeline::stitcher::{StitchedItem, test};
|
use crate::rooms::timeline::stitcher::StitchedItem;
|
||||||
|
|
||||||
pub(super) type TestEventId<'id> = &'id str;
|
pub(super) type TestEventId<'id> = &'id str;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user