fix(review): apply critical code-review optimizations for locks, memory, and responsiveness

This commit is contained in:
bleackstorm committed 2026-11-05 22:27:27 +01:00
1 parent 2d9be15713
commit a55ca0a25d
4 files changed
+156 -70

No files matched your search

+21 -4
View File
@@ -4,6 +4,7 @@ use parking_lot::Mutex;
use std::collections::VecDeque;
use std::fs::OpenOptions;
use std::io::Write;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::Arc;
const MAX_LOG_ENTRIES: usize = 1000;
@@ -23,12 +24,22 @@ pub struct LogEntry {
pub message: String,
}
#[derive(Default)]
pub struct LogBuffer {
pub entries: VecDeque<LogEntry>,
pub error_count: usize,
pub warn_count: usize,
pub revision: u64,
pub revision: Arc<AtomicU64>,
}
impl Default for LogBuffer {
fn default() -> Self {
Self {
entries: VecDeque::new(),
error_count: 0,
warn_count: 0,
revision: Arc::new(AtomicU64::new(0)),
}
}
}
/// Logger centralisé capturant tous les événements et erreurs pour l'interface graphique
@@ -110,10 +121,16 @@ impl Log for GuiLogger {
}
if lock.entries.len() >= MAX_LOG_ENTRIES {
lock.entries.pop_front();
if let Some(old) = lock.entries.pop_front() {
match old.level {
Level::Error => lock.error_count = lock.error_count.saturating_sub(1),
Level::Warn => lock.warn_count = lock.warn_count.saturating_sub(1),
_ => {}
}
}
}
lock.entries.push_back(entry);
lock.revision = lock.revision.wrapping_add(1);
lock.revision.fetch_add(1, Ordering::Release);
}
fn flush(&self) {}