Files
mcp-memory/server/src/handlers/utils.rs
T
Riz Ashraf 37003be620 refactor: apply rust best practices and fix memory optimizations
- Optimized memory allocation in router.rs by offloading JSON serialization to spawn_blocking and using references.
- Prevented full graph duplication on startup in state.rs index rebuild.
- Eliminated massive String allocations in QueryGraphPathHandler BFS loops.
- Avoided temporary Strings in VisualizeGraphHandler via inline writing.
- Fixed O(N) full-graph deduplication in MergeEntitiesHandler to scale efficiently.
2026-09-22 22:01:38 +01:00

39 lines
1.1 KiB
Rust

pub fn contains_ignore_ascii_case(haystack: &str, needle: &str) -> bool {
if needle.is_empty() {
return true;
}
haystack
.as_bytes()
.windows(needle.len())
.any(|w| w.eq_ignore_ascii_case(needle.as_bytes()))
}
pub fn now_secs() -> u64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_secs()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_contains_ignore_ascii_case() {
assert!(contains_ignore_ascii_case("Hello World", "world"));
assert!(contains_ignore_ascii_case("Hello World", "HELLO"));
assert!(contains_ignore_ascii_case("test", ""));
assert!(!contains_ignore_ascii_case("test", "testing"));
assert!(!contains_ignore_ascii_case("Hello", "world"));
}
#[test]
fn test_now_secs() {
let t1 = now_secs();
assert!(t1 > 1700000000); // Sanity check for recent epoch
std::thread::sleep(std::time::Duration::from_millis(1000));
let t2 = now_secs();
assert!(t2 >= t1);
}
}