Skip to content

Commit 974fa44

Browse files
authored
[bibtex] Refactor string pool (#1308)
2 parents 14aefdc + 3afa239 commit 974fa44

13 files changed

Lines changed: 908 additions & 808 deletions

File tree

crates/engine_bibtex/src/auxi.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ use crate::{
1313
print_confusion, print_overflow, AuxTy,
1414
},
1515
peekable::PeekableInput,
16-
pool::StringPool,
16+
pool::{StrNumber, StringPool},
1717
scan::Scan,
18-
Bibtex, BibtexError, File, GlobalItems, StrIlk, StrNumber,
18+
Bibtex, BibtexError, File, GlobalItems, StrIlk,
1919
};
2020
use std::ffi::CString;
2121
use tectonic_bridge_core::FileFormat;
@@ -105,7 +105,7 @@ fn aux_bib_data_command(
105105

106106
let file = &buffers.buffer(BufTy::Base)
107107
[buffers.offset(BufTy::Base, 1)..buffers.offset(BufTy::Base, 2)];
108-
let res = pool.lookup_str_insert(ctx, hash, file, HashExtra::BibFile)?;
108+
let res = hash.lookup_str_insert(ctx, pool, file, HashExtra::BibFile)?;
109109
if res.exists {
110110
ctx.write_logs("This database file appears more than once: ");
111111
print_bib_name(ctx, pool, hash.text(res.loc))?;
@@ -176,7 +176,7 @@ fn aux_bib_style_command(
176176

177177
let file = &buffers.buffer(BufTy::Base)
178178
[buffers.offset(BufTy::Base, 1)..buffers.offset(BufTy::Base, 2)];
179-
let res = pool.lookup_str_insert(ctx, hash, file, HashExtra::BstFile)?;
179+
let res = hash.lookup_str_insert(ctx, pool, file, HashExtra::BstFile)?;
180180
if res.exists {
181181
ctx.write_logs("Already encountered style file");
182182
print_confusion(ctx);
@@ -276,15 +276,15 @@ fn aux_citation_command(
276276
let lc_cite = &mut buffers.buffer_mut(BufTy::Ex)[range];
277277
lc_cite.make_ascii_lowercase();
278278

279-
let lc_res = pool.lookup_str_insert(ctx, hash, lc_cite, HashExtra::LcCite(0))?;
279+
let lc_res = hash.lookup_str_insert(ctx, pool, lc_cite, HashExtra::LcCite(0))?;
280280
if lc_res.exists {
281281
let HashExtra::LcCite(cite_loc) = hash.node(lc_res.loc).extra else {
282282
panic!("LcCite lookup didn't have LcCite extra");
283283
};
284284

285285
let cite = &buffers.buffer(BufTy::Base)
286286
[buffers.offset(BufTy::Base, 1)..buffers.offset(BufTy::Base, 2)];
287-
let uc_res = pool.lookup_str(hash, cite, StrIlk::Cite);
287+
let uc_res = hash.lookup_str(pool, cite, StrIlk::Cite);
288288
if !uc_res.exists {
289289
let HashExtra::Cite(cite) = hash.node(cite_loc).extra else {
290290
panic!("LcCite location didn't have a Cite extra");
@@ -301,7 +301,7 @@ fn aux_citation_command(
301301
} else {
302302
let cite = &buffers.buffer(BufTy::Base)
303303
[buffers.offset(BufTy::Base, 1)..buffers.offset(BufTy::Base, 2)];
304-
let uc_res = pool.lookup_str_insert(ctx, hash, cite, HashExtra::Cite(0))?;
304+
let uc_res = hash.lookup_str_insert(ctx, pool, cite, HashExtra::Cite(0))?;
305305
if uc_res.exists {
306306
hash_cite_confusion(ctx);
307307
return Err(BibtexError::Fatal);
@@ -375,7 +375,7 @@ fn aux_input_command(
375375

376376
let file = &buffers.buffer(BufTy::Base)
377377
[buffers.offset(BufTy::Base, 1)..buffers.offset(BufTy::Base, 2)];
378-
let res = pool.lookup_str_insert(ctx, hash, file, HashExtra::AuxFile)?;
378+
let res = hash.lookup_str_insert(ctx, pool, file, HashExtra::AuxFile)?;
379379
if res.exists {
380380
ctx.write_logs("Already encountered file ");
381381
print_aux_name(ctx, pool, hash.text(res.loc))?;
@@ -421,8 +421,8 @@ pub(crate) fn get_aux_command_and_process(
421421
let line = &globals.buffers.buffer(BufTy::Base)
422422
[globals.buffers.offset(BufTy::Base, 1)..globals.buffers.offset(BufTy::Base, 2)];
423423
let res = globals
424-
.pool
425-
.lookup_str(globals.hash, line, StrIlk::AuxCommand);
424+
.hash
425+
.lookup_str(globals.pool, line, StrIlk::AuxCommand);
426426

427427
if res.exists {
428428
let HashExtra::AuxCommand(cmd) = globals.hash.node(res.loc).extra else {

crates/engine_bibtex/src/bibs.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use crate::{
99
print_confusion,
1010
},
1111
peekable::input_ln,
12-
pool::StringPool,
12+
pool::{StrNumber, StringPool},
1313
scan::{scan_and_store_the_field_value_and_eat_white, scan_identifier, Scan, ScanRes},
14-
BibNumber, Bibtex, BibtexError, File, GlobalItems, HashPointer, StrIlk, StrNumber,
14+
BibNumber, Bibtex, BibtexError, File, GlobalItems, HashPointer, StrIlk,
1515
};
1616

1717
#[derive(Copy, Clone, Debug, PartialEq)]
@@ -191,8 +191,8 @@ pub(crate) fn get_bib_command_or_entry_and_process(
191191
bib_cmd.make_ascii_lowercase();
192192

193193
let res = globals
194-
.pool
195-
.lookup_str(globals.hash, bib_cmd, StrIlk::BibCommand);
194+
.hash
195+
.lookup_str(globals.pool, bib_cmd, StrIlk::BibCommand);
196196

197197
let mut lc_cite_loc = 0;
198198

@@ -351,11 +351,11 @@ pub(crate) fn get_bib_command_or_entry_and_process(
351351
bib_macro.make_ascii_lowercase();
352352

353353
// let text = globals.hash.text(res.loc);
354-
let res = globals.pool.lookup_str_insert(
354+
let res = globals.hash.lookup_str_insert(
355355
ctx,
356-
globals.hash,
356+
globals.pool,
357357
bib_macro,
358-
HashExtra::Macro(0),
358+
HashExtra::Macro(StrNumber::default()),
359359
)?;
360360
// TODO: Insert overwriting?
361361
globals.hash.node_mut(res.loc).extra = HashExtra::Macro(globals.hash.text(res.loc));
@@ -439,7 +439,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
439439

440440
let range = globals.buffers.offset(BufTy::Base, 1)..globals.buffers.offset(BufTy::Base, 2);
441441
let bst_fn = &mut globals.buffers.buffer_mut(BufTy::Base)[range];
442-
let bst_res = globals.pool.lookup_str(globals.hash, bst_fn, StrIlk::BstFn);
442+
let bst_res = globals.hash.lookup_str(globals.pool, bst_fn, StrIlk::BstFn);
443443

444444
let type_exists = if bst_res.exists {
445445
matches!(
@@ -515,12 +515,12 @@ pub(crate) fn get_bib_command_or_entry_and_process(
515515

516516
let lc_res = if ctx.all_entries {
517517
globals
518-
.pool
519-
.lookup_str_insert(ctx, globals.hash, lc_cite, HashExtra::LcCite(0))?
518+
.hash
519+
.lookup_str_insert(ctx, globals.pool, lc_cite, HashExtra::LcCite(0))?
520520
} else {
521521
globals
522-
.pool
523-
.lookup_str(globals.hash, lc_cite, StrIlk::LcCite)
522+
.hash
523+
.lookup_str(globals.pool, lc_cite, StrIlk::LcCite)
524524
};
525525

526526
let mut res = lc_res;
@@ -546,9 +546,9 @@ pub(crate) fn get_bib_command_or_entry_and_process(
546546
let range = globals.buffers.offset(BufTy::Base, 1)
547547
..globals.buffers.offset(BufTy::Base, 2);
548548
let cite = &globals.buffers.buffer(BufTy::Base)[range];
549-
let uc_res = globals.pool.lookup_str_insert(
549+
let uc_res = globals.hash.lookup_str_insert(
550550
ctx,
551-
globals.hash,
551+
globals.pool,
552552
cite,
553553
HashExtra::Cite(0),
554554
);
@@ -578,8 +578,8 @@ pub(crate) fn get_bib_command_or_entry_and_process(
578578
lc_cite.make_ascii_lowercase();
579579

580580
let lc_res2 = globals
581-
.pool
582-
.lookup_str(globals.hash, lc_cite, StrIlk::LcCite);
581+
.hash
582+
.lookup_str(globals.pool, lc_cite, StrIlk::LcCite);
583583

584584
res = lc_res2;
585585

@@ -637,8 +637,8 @@ pub(crate) fn get_bib_command_or_entry_and_process(
637637
[globals.buffers.offset(BufTy::Base, 1)..globals.buffers.offset(BufTy::Base, 2)];
638638
let res =
639639
globals
640-
.pool
641-
.lookup_str_insert(ctx, globals.hash, cite, HashExtra::Cite(0))?;
640+
.hash
641+
.lookup_str_insert(ctx, globals.pool, cite, HashExtra::Cite(0))?;
642642
if res.exists {
643643
hash_cite_confusion(ctx);
644644
return Err(BibtexError::Fatal);
@@ -744,7 +744,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
744744
let bst_fn = &mut globals.buffers.buffer_mut(BufTy::Base)[range];
745745
bst_fn.make_ascii_lowercase();
746746

747-
let res = globals.pool.lookup_str(globals.hash, bst_fn, StrIlk::BstFn);
747+
let res = globals.hash.lookup_str(globals.pool, bst_fn, StrIlk::BstFn);
748748

749749
*field_name_loc = res.loc;
750750
if res.exists {

0 commit comments

Comments
 (0)