Skip to content

Commit

Permalink
Swap debug logging lookup maps with IntHashMaps
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtread committed Dec 6, 2023
1 parent b076afc commit 94f676f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/utils/components.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use super::hashing::IntHashMap;

/// Key created from a component and command
pub type ComponentKey = u32;
Expand All @@ -15,8 +15,8 @@ static COMPONENT_NAMES: &[(u16, &str)] = &[
(game_reporting::COMPONENT, "GameReporting"),
(user_sessions::COMPONENT, "UserSessions"),
];
static mut COMMANDS: Option<HashMap<ComponentKey, &'static str>> = None;
static mut NOTIFICATIONS: Option<HashMap<ComponentKey, &'static str>> = None;
static mut COMMANDS: Option<IntHashMap<ComponentKey, &'static str>> = None;
static mut NOTIFICATIONS: Option<IntHashMap<ComponentKey, &'static str>> = None;

// Packets that will have their content omitted for debug logging
#[rustfmt::skip]
Expand Down Expand Up @@ -74,7 +74,6 @@ pub mod authentication {
pub const COMPONENT: u16 = 0x1;

// Commands

pub const CREATE_ACCOUNT: u16 = 0xA;
pub const UPDATE_ACCOUNT: u16 = 0x14;
pub const UPDATE_PARENTAL_EMAIL: u16 = 0x1C;
Expand Down Expand Up @@ -400,7 +399,7 @@ pub mod user_sessions {
}

#[rustfmt::skip]
fn commands() -> HashMap<ComponentKey, &'static str> {
fn commands() -> IntHashMap<ComponentKey, &'static str> {
use authentication as a;
use game_manager as g;
use redirector as r;
Expand Down Expand Up @@ -617,7 +616,7 @@ fn commands() -> HashMap<ComponentKey, &'static str> {
}

#[rustfmt::skip]
fn notifications() -> HashMap<ComponentKey, &'static str> {
fn notifications() -> IntHashMap<ComponentKey, &'static str> {
use game_manager as g;
use messaging as m;
use game_reporting as gr;
Expand Down
1 change: 1 addition & 0 deletions src/utils/hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub fn verify_password(password: &str, hash: &str) -> bool {
argon2.verify_password(password.as_bytes(), &hash).is_ok()
}

/// Alias for a [`HashMap`] that used [`IntHasher`] as its [`Hasher`]
pub type IntHashMap<K, V> = HashMap<K, V, BuildHasherDefault<IntHasher>>;

/// Hasher implementation that directly uses an integer value
Expand Down

0 comments on commit 94f676f

Please sign in to comment.