diff --git a/rslib/src/decks/name.rs b/rslib/src/decks/name.rs index d694c4a74..2f8a30086 100644 --- a/rslib/src/decks/name.rs +++ b/rslib/src/decks/name.rs @@ -192,7 +192,7 @@ fn normalized_deck_name_component(comp: &str) -> Cow { } pub(crate) fn immediate_parent_name(machine_name: &str) -> Option<&str> { - machine_name.rsplitn(2, '\x1f').nth(1) + machine_name.rsplit_once('\x1f').map(|t| t.0) } #[cfg(test)] diff --git a/rslib/src/decks/tree.rs b/rslib/src/decks/tree.rs index bafccbc0d..3af8cc0b8 100644 --- a/rslib/src/decks/tree.rs +++ b/rslib/src/decks/tree.rs @@ -377,7 +377,7 @@ impl Collection { let mut missing = 0; for (_id, name) in names { parents.insert(UniCase::new(name.as_str())); - if let Some(immediate_parent) = name.rsplitn(2, "::").nth(1) { + if let Some((immediate_parent, _)) = name.rsplit_once("::") { let immediate_parent_uni = UniCase::new(immediate_parent); if !parents.contains(&immediate_parent_uni) { self.get_or_create_normal_deck(immediate_parent)?; diff --git a/rslib/src/notetype/schema11.rs b/rslib/src/notetype/schema11.rs index 0b6053fe7..f1e6b9911 100644 --- a/rslib/src/notetype/schema11.rs +++ b/rslib/src/notetype/schema11.rs @@ -57,15 +57,9 @@ pub struct NotetypeSchema11 { pub(crate) other: HashMap, } -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Default, Clone)] pub(crate) struct CardRequirementsSchema11(pub(crate) Vec); -impl Default for CardRequirementsSchema11 { - fn default() -> Self { - CardRequirementsSchema11(vec![]) - } -} - #[derive(Serialize_tuple, Deserialize, Debug, Clone)] pub(crate) struct CardRequirementSchema11 { pub(crate) card_ord: u16, diff --git a/rslib/src/scheduler/queue/builder/mod.rs b/rslib/src/scheduler/queue/builder/mod.rs index e4b642b3a..3703e6b7d 100644 --- a/rslib/src/scheduler/queue/builder/mod.rs +++ b/rslib/src/scheduler/queue/builder/mod.rs @@ -25,8 +25,6 @@ pub(crate) struct DueCard { pub note_id: NoteId, pub mtime: TimestampSecs, pub due: i32, - pub interval: u32, - pub hash: u64, pub current_deck_id: DeckId, pub original_deck_id: DeckId, pub kind: DueCardKind, @@ -122,7 +120,6 @@ impl QueueBuilder { mut self, top_deck_limits: RemainingLimits, learn_ahead_secs: i64, - selected_deck: DeckId, current_day: u32, ) -> CardQueues { self.sort_new(); @@ -164,7 +161,6 @@ impl QueueBuilder { main: main_iter.collect(), intraday_learning, learn_ahead_secs, - selected_deck, current_day, build_time: TimestampMillis::now(), current_learning_cutoff: now, @@ -333,7 +329,6 @@ impl Collection { let queues = queues.build( final_limits, self.learn_ahead_secs() as i64, - deck_id, timing.days_elapsed, ); diff --git a/rslib/src/scheduler/queue/learning.rs b/rslib/src/scheduler/queue/learning.rs index f1d6fbab3..40f5584de 100644 --- a/rslib/src/scheduler/queue/learning.rs +++ b/rslib/src/scheduler/queue/learning.rs @@ -1,8 +1,6 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use std::{cmp::Ordering, collections::VecDeque}; - use super::{undo::CutoffSnapshot, CardQueues}; use crate::{prelude::*, scheduler::timing::SchedTimingToday}; @@ -139,7 +137,9 @@ impl CardQueues { self.counts.learning += 1; } - let target_idx = binary_search_by(&self.intraday_learning, |e| e.due.cmp(&entry.due)) + let target_idx = self + .intraday_learning + .binary_search_by(|e| e.due.cmp(&entry.due)) .unwrap_or_else(|e| e); self.intraday_learning.insert(target_idx, entry); } @@ -171,20 +171,3 @@ impl CardQueues { .adding_secs(self.learn_ahead_secs) } } - -/// Adapted from the Rust stdlib VecDeque implementation; we can drop this after updating -/// to Rust 1.54.0 -fn binary_search_by<'a, F, T>(deque: &'a VecDeque, mut f: F) -> Result -where - F: FnMut(&'a T) -> Ordering, -{ - let (front, back) = deque.as_slices(); - - match back.first().map(|elem| f(elem)) { - Some(Ordering::Less) | Some(Ordering::Equal) => back - .binary_search_by(f) - .map(|idx| idx + front.len()) - .map_err(|idx| idx + front.len()), - _ => front.binary_search_by(f), - } -} diff --git a/rslib/src/scheduler/queue/mod.rs b/rslib/src/scheduler/queue/mod.rs index 9be920147..5bbacca5a 100644 --- a/rslib/src/scheduler/queue/mod.rs +++ b/rslib/src/scheduler/queue/mod.rs @@ -23,7 +23,6 @@ pub(crate) struct CardQueues { counts: Counts, main: VecDeque, intraday_learning: VecDeque, - selected_deck: DeckId, current_day: u32, learn_ahead_secs: i64, build_time: TimestampMillis, diff --git a/rslib/src/search/writer.rs b/rslib/src/search/writer.rs index 366781f3c..0b700d915 100644 --- a/rslib/src/search/writer.rs +++ b/rslib/src/search/writer.rs @@ -66,7 +66,7 @@ pub fn replace_search_node(mut existing: Vec, replacement: Node) -> String } pub fn write_nodes(nodes: &[Node]) -> String { - nodes.iter().map(|node| write_node(node)).collect() + nodes.iter().map(write_node).collect() } fn write_node(node: &Node) -> String { diff --git a/rslib/src/stats/card.rs b/rslib/src/stats/card.rs index 8f77a06c4..aebb4c548 100644 --- a/rslib/src/stats/card.rs +++ b/rslib/src/stats/card.rs @@ -43,11 +43,7 @@ impl Collection { total_secs, card_type: nt.get_template(card.template_idx)?.name.clone(), notetype: nt.name.clone(), - revlog: revlog - .iter() - .rev() - .map(|entry| stats_revlog_entry(entry)) - .collect(), + revlog: revlog.iter().rev().map(stats_revlog_entry).collect(), }) } diff --git a/rslib/src/storage/card/mod.rs b/rslib/src/storage/card/mod.rs index 23484cee8..72ac4fb56 100644 --- a/rslib/src/storage/card/mod.rs +++ b/rslib/src/storage/card/mod.rs @@ -182,8 +182,6 @@ impl super::SqliteStorage { mtime: row.get(3)?, current_deck_id: row.get(4)?, original_deck_id: row.get(5)?, - interval: 0, - hash: 0, kind: DueCardKind::Learning, }) } @@ -219,11 +217,9 @@ impl super::SqliteStorage { id: row.get(0)?, note_id: row.get(1)?, due: row.get(2).ok().unwrap_or_default(), - interval: row.get(3)?, mtime: row.get(4)?, current_deck_id: row.get(5)?, original_deck_id: row.get(6)?, - hash: 0, kind, }) { break; diff --git a/rslib/src/storage/deck/mod.rs b/rslib/src/storage/deck/mod.rs index bfcafafe9..5dbe57c46 100644 --- a/rslib/src/storage/deck/mod.rs +++ b/rslib/src/storage/deck/mod.rs @@ -305,7 +305,7 @@ impl SqliteStorage { self.db .prepare_cached(sql)? - .query_and_then(&*params, |row| row_to_due_counts(row))? + .query_and_then(&*params, row_to_due_counts)? .collect() } diff --git a/rslib/src/tags/mod.rs b/rslib/src/tags/mod.rs index b99728f55..7cb83b793 100644 --- a/rslib/src/tags/mod.rs +++ b/rslib/src/tags/mod.rs @@ -54,9 +54,9 @@ fn is_tag_separator(c: char) -> bool { } fn immediate_parent_name_unicase(tag_name: UniCase<&str>) -> Option> { - tag_name.rsplitn(2, '\x1f').nth(1).map(UniCase::new) + tag_name.rsplit_once('\x1f').map(|t| t.0).map(UniCase::new) } fn immediate_parent_name_str(tag_name: &str) -> Option<&str> { - tag_name.rsplitn(2, "::").nth(1) + tag_name.rsplit_once("::").map(|t| t.0) } diff --git a/rslib/src/template_filters.rs b/rslib/src/template_filters.rs index 49e540b8a..81b002668 100644 --- a/rslib/src/template_filters.rs +++ b/rslib/src/template_filters.rs @@ -195,7 +195,7 @@ return false;"> } fn tts_filter(filter_name: &str, text: &str, tr: &I18n) -> Cow<'static, str> { - let args = filter_name.splitn(2, ' ').nth(1).unwrap_or(""); + let args = filter_name.split_once(' ').map_or("", |t| t.1); let text = text.replace("[...]", &tr.card_templates_blank()); format!("[anki:tts][{}]{}[/anki:tts]", args, text).into()