1- use slotmap:: Key ;
21use crate :: {
32 buffer:: { BufTy , GlobalBuffer } ,
43 char_info:: LexClass ,
54 cite:: add_database_cite,
6- hash:: { BstFn , HashData , HashExtra } ,
5+ hash,
6+ hash:: { BstFn , HashData } ,
77 log:: {
88 bib_equals_sign_print, bib_err_print, bib_id_print, bib_one_of_two_print, bib_warn_print,
99 cite_key_disappeared_confusion, eat_bib_print, hash_cite_confusion, print_a_token,
@@ -12,7 +12,7 @@ use crate::{
1212 peekable:: input_ln,
1313 pool:: { StrNumber , StringPool } ,
1414 scan:: { scan_and_store_the_field_value_and_eat_white, scan_identifier, Scan , ScanRes } ,
15- Bibtex , BibtexError , File , GlobalItems , HashPointer , LookupRes , StrIlk ,
15+ Bibtex , BibtexError , File , GlobalItems , HashPointer , LookupRes ,
1616} ;
1717
1818#[ derive( Copy , Clone , Debug , PartialEq ) ]
@@ -129,8 +129,8 @@ pub(crate) fn compress_bib_white(
129129pub ( crate ) fn get_bib_command_or_entry_and_process (
130130 ctx : & mut Bibtex < ' _ , ' _ > ,
131131 globals : & mut GlobalItems < ' _ > ,
132- cur_macro_loc : & mut HashPointer ,
133- field_name_loc : & mut HashPointer ,
132+ cur_macro_loc : & mut HashPointer < hash :: Macro > ,
133+ field_name_loc : & mut HashPointer < BstFn > ,
134134) -> Result < ( ) , BibtexError > {
135135 let mut bib_command = None ;
136136
@@ -191,17 +191,12 @@ pub(crate) fn get_bib_command_or_entry_and_process(
191191 let bib_cmd = & mut globals. buffers . buffer_mut ( BufTy :: Base ) [ range] ;
192192 bib_cmd. make_ascii_lowercase ( ) ;
193193
194- let res = globals
195- . hash
196- . lookup_str ( globals. pool , bib_cmd, StrIlk :: BibCommand ) ;
194+ let res = globals. hash . lookup_str :: < BibCommand > ( globals. pool , bib_cmd) ;
197195
198196 let mut lc_cite_loc = HashPointer :: default ( ) ;
199197
200198 if let Some ( loc) = res {
201- let & HashExtra :: BibCommand ( cmd) = globals. hash . get ( loc) . extra ( ) else {
202- panic ! ( "BibCommand lookup didn't have BibCommand extra" ) ;
203- } ;
204-
199+ let & cmd = globals. hash . get ( loc) . extra ( ) ;
205200 bib_command = Some ( cmd) ;
206201 match cmd {
207202 BibCommand :: Comment => ( ) ,
@@ -352,13 +347,14 @@ pub(crate) fn get_bib_command_or_entry_and_process(
352347 bib_macro. make_ascii_lowercase ( ) ;
353348
354349 // let text = globals.hash.text(res.loc);
355- let res = globals. hash . lookup_str_insert (
356- globals. pool ,
357- bib_macro,
358- HashExtra :: Macro ( StrNumber :: default ( ) ) ,
359- ) ;
350+ let res =
351+ globals
352+ . hash
353+ . lookup_str_insert ( globals. pool , bib_macro, StrNumber :: default ( ) ) ;
360354 // TODO: Insert overwriting?
361- * globals. hash . get_mut ( res. loc ) . extra_mut ( ) = HashExtra :: Macro ( globals. hash . get ( res. loc ) . text ( ) ) ;
355+ globals
356+ . hash
357+ . set_extra ( res. loc , globals. hash . get ( res. loc ) . text ( ) ) ;
362358 * cur_macro_loc = res. loc ;
363359
364360 if !eat_bib_white_space ( ctx, globals. buffers , globals. bibs ) {
@@ -441,13 +437,8 @@ pub(crate) fn get_bib_command_or_entry_and_process(
441437 let bst_fn = & mut globals. buffers . buffer_mut ( BufTy :: Base ) [ range] ;
442438 let bst_res = globals
443439 . hash
444- . lookup_str ( globals. pool , bst_fn, StrIlk :: BstFn )
445- . filter ( |& loc| {
446- matches ! (
447- globals. hash. get( loc) . extra( ) ,
448- HashExtra :: BstFn ( BstFn :: Wizard ( _) )
449- )
450- } ) ;
440+ . lookup_str :: < BstFn > ( globals. pool , bst_fn)
441+ . filter ( |& loc| matches ! ( globals. hash. get( loc) . extra( ) , BstFn :: Wizard ( _) , ) ) ;
451442
452443 if !eat_bib_white_space ( ctx, globals. buffers , globals. bibs ) {
453444 eat_bib_print (
@@ -515,11 +506,11 @@ pub(crate) fn get_bib_command_or_entry_and_process(
515506 let lc_res = if ctx. all_entries {
516507 globals
517508 . hash
518- . lookup_str_insert ( globals. pool , lc_cite, HashExtra :: LcCite ( HashPointer :: default ( ) ) )
509+ . lookup_str_insert ( globals. pool , lc_cite, HashPointer :: default ( ) )
519510 } else {
520511 globals
521512 . hash
522- . lookup_str ( globals. pool , lc_cite, StrIlk :: LcCite )
513+ . lookup_str :: < hash :: LcCite > ( globals. pool , lc_cite)
523514 . map_or (
524515 LookupRes {
525516 loc : HashPointer :: default ( ) ,
@@ -529,17 +520,13 @@ pub(crate) fn get_bib_command_or_entry_and_process(
529520 )
530521 } ;
531522
532- let mut res = lc_res;
523+ let mut cite_exists = lc_res. exists ;
533524
534525 // TODO: Improve this tangled control flow
535526 let mut inner = || {
536527 if lc_res. exists {
537- let & HashExtra :: LcCite ( cite_loc) = globals. hash . get ( lc_res. loc ) . extra ( ) else {
538- panic ! ( "LcCite lookup didn't have LcCite extra" ) ;
539- } ;
540- let & HashExtra :: Cite ( cite) = globals. hash . get ( cite_loc) . extra ( ) else {
541- panic ! ( "LcCite location didn't have Cite extra" ) ;
542- } ;
528+ let & cite_loc = globals. hash . get ( lc_res. loc ) . extra ( ) ;
529+ let & cite = globals. hash . get ( cite_loc) . extra ( ) ;
543530
544531 globals. cites . set_entry_ptr ( cite) ;
545532 let entry_ptr = globals. cites . entry_ptr ( ) ;
@@ -552,23 +539,23 @@ pub(crate) fn get_bib_command_or_entry_and_process(
552539 let range = globals. buffers . offset ( BufTy :: Base , 1 )
553540 ..globals. buffers . offset ( BufTy :: Base , 2 ) ;
554541 let cite = & globals. buffers . buffer ( BufTy :: Base ) [ range] ;
555- let uc_res = globals. hash . lookup_str_insert (
556- globals. pool ,
557- cite,
558- HashExtra :: Cite ( 0 ) ,
559- ) ;
542+ let uc_res =
543+ globals
544+ . hash
545+ . lookup_str_insert :: < hash:: Cite > ( globals. pool , cite, 0 ) ;
560546
561- res = uc_res;
547+ cite_exists = uc_res. exists ;
562548
563549 if !uc_res. exists {
564- * globals. hash . get_mut ( lc_res. loc ) . extra_mut ( ) = HashExtra :: LcCite ( uc_res. loc ) ;
565- * globals. hash . get_mut ( uc_res. loc ) . extra_mut ( ) = HashExtra :: Cite ( entry_ptr) ;
550+ globals. hash . set_extra ( lc_res. loc , uc_res. loc ) ;
551+ globals. hash . set_extra ( uc_res. loc , entry_ptr) ;
566552 globals
567553 . cites
568554 . set_cite ( entry_ptr, globals. hash . get ( uc_res. loc ) . text ( ) ) ;
569- res . exists = true ;
555+ cite_exists = true ;
570556 }
571557 }
558+ // Break out of if
572559 return None ;
573560 }
574561 } else if !globals. cites . exists ( entry_ptr) {
@@ -579,7 +566,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
579566
580567 let lc_res2 = globals
581568 . hash
582- . lookup_str ( globals. pool , lc_cite, StrIlk :: LcCite )
569+ . lookup_str :: < hash :: LcCite > ( globals. pool , lc_cite)
583570 . map_or (
584571 LookupRes {
585572 loc : HashPointer :: default ( ) ,
@@ -588,7 +575,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
588575 |loc| LookupRes { loc, exists : true } ,
589576 ) ;
590577
591- res = lc_res2;
578+ cite_exists = lc_res2. exists ;
592579
593580 if !lc_res2. exists {
594581 cite_key_disappeared_confusion ( ctx) ;
@@ -622,12 +609,10 @@ pub(crate) fn get_bib_command_or_entry_and_process(
622609 }
623610
624611 let store_entry = if ctx. all_entries {
625- if res . exists {
612+ if cite_exists {
626613 if globals. cites . entry_ptr ( ) >= globals. cites . all_marker ( ) {
627614 globals. cites . set_exists ( globals. cites . entry_ptr ( ) , true ) ;
628- let & HashExtra :: LcCite ( cite_loc) = globals. hash . get ( lc_res. loc ) . extra ( ) else {
629- panic ! ( "LcCite lookup didn't have LcCite extra" ) ;
630- } ;
615+ let & cite_loc = globals. hash . get ( lc_res. loc ) . extra ( ) ;
631616 globals. cites . set_entry_ptr ( globals. cites . ptr ( ) ) ;
632617 let num = add_database_cite (
633618 globals. cites ,
@@ -642,10 +627,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
642627 } else {
643628 let cite = & globals. buffers . buffer ( BufTy :: Base )
644629 [ globals. buffers . offset ( BufTy :: Base , 1 ) ..globals. buffers . offset ( BufTy :: Base , 2 ) ] ;
645- let res =
646- globals
647- . hash
648- . lookup_str_insert ( globals. pool , cite, HashExtra :: Cite ( 0 ) ) ;
630+ let res = globals. hash . lookup_str_insert ( globals. pool , cite, 0 ) ;
649631 if res. exists {
650632 hash_cite_confusion ( ctx) ;
651633 return Err ( BibtexError :: Fatal ) ;
@@ -663,7 +645,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
663645 }
664646 true
665647 } else {
666- res . exists
648+ cite_exists
667649 } ;
668650
669651 if store_entry {
@@ -749,15 +731,10 @@ pub(crate) fn get_bib_command_or_entry_and_process(
749731 let bst_fn = & mut globals. buffers . buffer_mut ( BufTy :: Base ) [ range] ;
750732 bst_fn. make_ascii_lowercase ( ) ;
751733
752- let res = globals. hash . lookup_str ( globals. pool , bst_fn, StrIlk :: BstFn ) ;
734+ let res = globals. hash . lookup_str :: < BstFn > ( globals. pool , bst_fn) ;
753735
754736 match res {
755- Some ( loc)
756- if matches ! (
757- globals. hash. get( loc) . extra( ) ,
758- HashExtra :: BstFn ( BstFn :: Field ( _) )
759- ) =>
760- {
737+ Some ( loc) if matches ! ( globals. hash. get( loc) . extra( ) , BstFn :: Field ( _) , ) => {
761738 * field_name_loc = loc;
762739 store_field = true ;
763740 }
0 commit comments