Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::HashMap;

use ratatui::{
backend::Backend,
crossterm::event::{KeyCode, KeyEvent},
Expand All @@ -9,6 +7,7 @@ use ratatui::{
widgets::{Block, Borders, Padding, Paragraph},
Frame, Terminal,
};
use rustc_hash::FxHashMap;

use crate::{
color::{ColorTheme, GraphColorSet},
Expand Down Expand Up @@ -70,7 +69,7 @@ impl<'a> App<'a> {
initial_selection: InitialSelection,
tx: Sender,
) -> Self {
let mut ref_name_to_commit_index_map = HashMap::new();
let mut ref_name_to_commit_index_map = FxHashMap::default();
let commits = graph
.commits
.iter()
Expand Down
14 changes: 7 additions & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::{
collections::HashMap,
env,
path::{Path, PathBuf},
};

use garde::Validate;
use rustc_hash::FxHashMap;
use serde::Deserialize;
use smart_default::SmartDefault;
use umbra::optional;
Expand Down Expand Up @@ -141,7 +141,7 @@ pub struct CoreSearchConfig {
#[derive(Debug, Clone, PartialEq, Eq, SmartDefault, Validate)]
pub struct CoreUserCommandConfig {
#[garde(dive)]
#[default(HashMap::from([("1".into(), UserCommand {
#[default(FxHashMap::from_iter([("1".into(), UserCommand {
name: "git diff".into(),
commands: vec![
"git".into(),
Expand All @@ -152,7 +152,7 @@ pub struct CoreUserCommandConfig {
"{{target_hash}}".into(),
],
})]))]
pub commands: HashMap<String, UserCommand>,
pub commands: FxHashMap<String, UserCommand>,
#[garde(range(min = 0))]
#[default = 4]
pub tab_width: u16,
Expand All @@ -179,7 +179,7 @@ impl<'de> Deserialize<'de> for OptionalCoreUserCommandConfig {
where
V: MapAccess<'de>,
{
let mut commands = HashMap::new();
let mut commands = FxHashMap::default();
let mut tab_width = None;

while let Some(key) = map.next_key::<String>()? {
Expand Down Expand Up @@ -379,7 +379,7 @@ mod tests {
fuzzy: false,
},
user_command: CoreUserCommandConfig {
commands: HashMap::from([(
commands: FxHashMap::from_iter([(
"1".into(),
UserCommand {
name: "git diff".into(),
Expand Down Expand Up @@ -491,7 +491,7 @@ mod tests {
fuzzy: true,
},
user_command: CoreUserCommandConfig {
commands: HashMap::from([
commands: FxHashMap::from_iter([
(
"1".into(),
UserCommand {
Expand Down Expand Up @@ -578,7 +578,7 @@ mod tests {
fuzzy: false,
},
user_command: CoreUserCommandConfig {
commands: HashMap::from([(
commands: FxHashMap::from_iter([(
"1".into(),
UserCommand {
name: "git diff".into(),
Expand Down
32 changes: 17 additions & 15 deletions src/git.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::{
collections::HashMap,
hash::Hash,
io::{BufRead, BufReader},
path::{Path, PathBuf},
process::{Command, Stdio},
};

use chrono::{DateTime, FixedOffset};
use rustc_hash::FxHashMap;

use crate::Result;

Expand Down Expand Up @@ -104,10 +104,10 @@ pub enum SortCommit {
Topological,
}

type CommitMap = HashMap<CommitHash, Commit>;
type CommitsMap = HashMap<CommitHash, Vec<CommitHash>>;
type CommitMap = FxHashMap<CommitHash, Commit>;
type CommitsMap = FxHashMap<CommitHash, Vec<CommitHash>>;

type RefMap = HashMap<CommitHash, Vec<Ref>>;
type RefMap = FxHashMap<CommitHash, Vec<Ref>>;

#[derive(Debug)]
pub struct Repository {
Expand Down Expand Up @@ -381,8 +381,8 @@ fn parse_parent_commit_hashes(s: &str) -> Vec<CommitHash> {
}

fn build_commits_maps(commits: &Vec<Commit>) -> (CommitsMap, CommitsMap) {
let mut parents_map: CommitsMap = HashMap::new();
let mut children_map: CommitsMap = HashMap::new();
let mut parents_map: CommitsMap = FxHashMap::default();
let mut children_map: CommitsMap = FxHashMap::default();
for commit in commits {
let hash = &commit.commit_hash;
for parent_hash in &commit.parent_commit_hashes {
Expand Down Expand Up @@ -411,12 +411,14 @@ fn merge_stashes_to_commits(commits: Vec<Commit>, stashes: Vec<Commit>) -> Vec<C
// Stash commit has multiple parent commits, but the first parent commit is the commit that the stash was created from.
// If the first parent commit is not found, the stash commit is ignored.
let mut ret = Vec::new();
let mut statsh_map: HashMap<CommitHash, Vec<Commit>> =
stashes.into_iter().fold(HashMap::new(), |mut acc, commit| {
let parent = commit.parent_commit_hashes[0].clone();
acc.entry(parent).or_default().push(commit);
acc
});
let mut statsh_map: FxHashMap<CommitHash, Vec<Commit>> =
stashes
.into_iter()
.fold(FxHashMap::default(), |mut acc, commit| {
let parent = commit.parent_commit_hashes[0].clone();
acc.entry(parent).or_default().push(commit);
acc
});
for commit in commits {
if let Some(stashes) = statsh_map.remove(&commit.commit_hash) {
for stash in stashes {
Expand All @@ -443,8 +445,8 @@ fn load_refs(path: &Path) -> (RefMap, Head) {

let reader = BufReader::new(stdout);

let mut ref_map = RefMap::new();
let mut tag_map: HashMap<String, Ref> = HashMap::new();
let mut ref_map = RefMap::default();
let mut tag_map: FxHashMap<String, Ref> = FxHashMap::default();
let mut head: Option<Head> = None;

for line in reader.lines() {
Expand Down Expand Up @@ -504,7 +506,7 @@ fn load_stashes_as_refs(path: &Path) -> RefMap {

let reader = BufReader::new(stdout);

let mut ref_map = RefMap::new();
let mut ref_map = RefMap::default();

for line in reader.lines() {
let line = line.unwrap();
Expand Down
10 changes: 5 additions & 5 deletions src/keybind.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::collections::HashMap;
use std::ops::{Deref, DerefMut};

use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use rustc_hash::FxHashMap;
use serde::{de::Deserializer, Deserialize};

use crate::event::UserEvent;

const DEFAULT_KEY_BIND: &str = include_str!("../assets/default-keybind.toml");

#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct KeyBind(HashMap<KeyEvent, UserEvent>);
pub struct KeyBind(FxHashMap<KeyEvent, UserEvent>);

impl Deref for KeyBind {
type Target = HashMap<KeyEvent, UserEvent>;
type Target = FxHashMap<KeyEvent, UserEvent>;

fn deref(&self) -> &Self::Target {
&self.0
Expand Down Expand Up @@ -70,8 +70,8 @@ impl<'de> Deserialize<'de> for KeyBind {
where
D: Deserializer<'de>,
{
let parsed_map = HashMap::<UserEvent, Vec<String>>::deserialize(deserializer)?;
let mut key_map = HashMap::<KeyEvent, UserEvent>::new();
let parsed_map = FxHashMap::<UserEvent, Vec<String>>::deserialize(deserializer)?;
let mut key_map = FxHashMap::<KeyEvent, UserEvent>::default();
for (user_event, key_events) in parsed_map {
for key_event_str in key_events {
let key_event = match parse_key_event(&key_event_str) {
Expand Down
11 changes: 5 additions & 6 deletions src/widget/commit_list.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::HashMap;

use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher};
use laurier::highlight::highlight_matched_text;
use once_cell::sync::Lazy;
Expand All @@ -11,6 +9,7 @@ use ratatui::{
text::{Line, Span},
widgets::{List, ListItem, StatefulWidget, Widget},
};
use rustc_hash::FxHashMap;
use tui_input::{backend::crossterm::EventHandler, Input};

use crate::{
Expand Down Expand Up @@ -78,7 +77,7 @@ pub enum TransientMessage {

#[derive(Debug, Default, Clone)]
struct SearchMatch {
refs: HashMap<String, SearchMatchPosition>,
refs: FxHashMap<String, SearchMatchPosition>,
subject: Option<SearchMatchPosition>,
author_name: Option<SearchMatchPosition>,
commit_hash: Option<SearchMatchPosition>,
Expand Down Expand Up @@ -185,7 +184,7 @@ pub struct CommitListState<'a> {
graph_cell_width: u16,
head: &'a Head,

ref_name_to_commit_index_map: HashMap<&'a str, usize>,
ref_name_to_commit_index_map: FxHashMap<&'a str, usize>,

search_state: SearchState,
search_input: Input,
Expand All @@ -206,7 +205,7 @@ impl<'a> CommitListState<'a> {
graph_image_manager: GraphImageManager<'a>,
graph_cell_width: u16,
head: &'a Head,
ref_name_to_commit_index_map: HashMap<&'a str, usize>,
ref_name_to_commit_index_map: FxHashMap<&'a str, usize>,
default_ignore_case: bool,
default_fuzzy: bool,
) -> CommitListState<'a> {
Expand Down Expand Up @@ -961,7 +960,7 @@ impl CommitList<'_> {
fn refs_spans<'a>(
commit_info: &'a CommitInfo,
head: &'a Head,
refs_matches: &'a HashMap<String, SearchMatchPosition>,
refs_matches: &'a FxHashMap<String, SearchMatchPosition>,
color_theme: &'a ColorTheme,
) -> Vec<Span<'a>> {
let refs = &commit_info.refs;
Expand Down