1- #![ allow( dead_code) ]
21use std:: collections:: HashMap ;
32use std:: io:: { Read , Write } ;
43use std:: path:: PathBuf ;
@@ -7,7 +6,6 @@ use std::sync::Arc;
76use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
87
98use rayon:: prelude:: * ;
10- use structopt:: StructOpt ;
119use git2:: { Diff , DiffFormat , DiffOptions , Repository , Tree } ;
1210use anyhow:: { Context , Result } ;
1311use thiserror:: Error ;
@@ -17,7 +15,7 @@ use crate::model::Model;
1715use crate :: profile;
1816
1917// Constants
20- const MAX_POOL_SIZE : usize = 1000 ;
18+
2119const DEFAULT_STRING_CAPACITY : usize = 8192 ;
2220const PARALLEL_CHUNK_SIZE : usize = 25 ;
2321const ESTIMATED_FILES_COUNT : usize = 100 ;
@@ -44,46 +42,6 @@ pub enum HookError {
4442 Anyhow ( #[ from] anyhow:: Error )
4543}
4644
47- // CLI Arguments
48- #[ derive( StructOpt , Debug ) ]
49- #[ structopt( name = "commit-msg-hook" , about = "A tool for generating commit messages." ) ]
50- pub struct Args {
51- pub commit_msg_file : PathBuf ,
52-
53- #[ structopt( short = "t" , long = "type" ) ]
54- pub commit_type : Option < String > ,
55-
56- #[ structopt( short = "s" , long = "sha1" ) ]
57- pub sha1 : Option < String >
58- }
59-
60- // Memory management
61- #[ derive( Debug ) ]
62- struct StringPool {
63- strings : Vec < String > ,
64- capacity : usize
65- }
66-
67- impl StringPool {
68- fn new ( capacity : usize ) -> Self {
69- Self { strings : Vec :: with_capacity ( capacity) , capacity }
70- }
71-
72- fn get ( & mut self ) -> String {
73- self
74- . strings
75- . pop ( )
76- . unwrap_or_else ( || String :: with_capacity ( self . capacity ) )
77- }
78-
79- fn put ( & mut self , mut string : String ) {
80- string. clear ( ) ;
81- if self . strings . len ( ) < MAX_POOL_SIZE {
82- self . strings . push ( string) ;
83- }
84- }
85- }
86-
8745// File operations traits
8846pub trait FilePath {
8947 fn is_empty ( & self ) -> Result < bool > {
@@ -364,10 +322,6 @@ impl PatchDiff for Diff<'_> {
364322 // Pre-allocate HashMap with estimated capacity
365323 let mut files = HashMap :: with_capacity ( ESTIMATED_FILES_COUNT ) ;
366324
367- // Use pre-sized buffers to avoid reallocations
368- const BUFFER_SIZE : usize = 64 ; // Hold context prefix strings
369- static CONTEXT_PREFIX : & str = "context: " ;
370-
371325 // Create thread-local cache for paths to avoid allocations
372326 thread_local ! {
373327 static PATH_CACHE : std:: cell:: RefCell <HashMap <PathBuf , ( ) >> =
@@ -676,49 +630,3 @@ impl PatchRepository for Repository {
676630 . minimal ( true ) ;
677631 }
678632}
679-
680- #[ cfg( test) ]
681- mod tests {
682- use super :: * ;
683-
684- #[ test]
685- fn test_string_pool_new ( ) {
686- let pool = StringPool :: new ( 100 ) ;
687- assert_eq ! ( pool. strings. len( ) , 0 ) ;
688- assert_eq ! ( pool. capacity, 100 ) ;
689- }
690-
691- #[ test]
692- fn test_string_pool_put_and_get ( ) {
693- let mut pool = StringPool :: new ( 10 ) ;
694- let mut s1 = String :: with_capacity ( 10 ) ;
695- s1. push_str ( "test" ) ;
696- pool. put ( s1) ;
697-
698- assert_eq ! ( pool. strings. len( ) , 1 ) ;
699-
700- let s2 = pool. get ( ) ;
701- assert_eq ! ( s2. capacity( ) , 10 ) ;
702- assert_eq ! ( s2. len( ) , 0 ) ;
703- assert_eq ! ( pool. strings. len( ) , 0 ) ;
704- }
705-
706- #[ test]
707- fn test_string_pool_limit ( ) {
708- let mut pool = StringPool :: new ( 10 ) ;
709-
710- for _ in 0 ..150 {
711- pool. put ( String :: with_capacity ( 10 ) ) ;
712- }
713-
714- assert_eq ! ( pool. strings. len( ) , 150 ) ;
715- }
716- }
717-
718- #[ test]
719- fn test_string_pool_get ( ) {
720- let mut pool = StringPool :: new ( 10 ) ;
721- let s1 = pool. get ( ) ;
722- assert_eq ! ( s1. capacity( ) , 10 ) ;
723- assert_eq ! ( s1. len( ) , 0 ) ;
724- }
0 commit comments