Skip to content

Commit 2742e7a

Browse files
committed
Simplify and encapsulate StringPool interface.
- Other files no longer need access to internal fields - Hash-related functions moved to HashData - Cursor-based API should allow no-allocation writes to the string pool
1 parent 14aefdc commit 2742e7a

13 files changed

Lines changed: 853 additions & 768 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::{StringPool, StrNumber},
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 & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ use crate::{
1111
peekable::input_ln,
1212
pool::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
};
16+
use crate::pool::StrNumber;
1617

1718
#[derive(Copy, Clone, Debug, PartialEq)]
1819
pub(crate) enum BibCommand {
@@ -191,8 +192,8 @@ pub(crate) fn get_bib_command_or_entry_and_process(
191192
bib_cmd.make_ascii_lowercase();
192193

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

197198
let mut lc_cite_loc = 0;
198199

@@ -351,11 +352,11 @@ pub(crate) fn get_bib_command_or_entry_and_process(
351352
bib_macro.make_ascii_lowercase();
352353

353354
// let text = globals.hash.text(res.loc);
354-
let res = globals.pool.lookup_str_insert(
355+
let res = globals.hash.lookup_str_insert(
355356
ctx,
356-
globals.hash,
357+
globals.pool,
357358
bib_macro,
358-
HashExtra::Macro(0),
359+
HashExtra::Macro(StrNumber::default()),
359360
)?;
360361
// TODO: Insert overwriting?
361362
globals.hash.node_mut(res.loc).extra = HashExtra::Macro(globals.hash.text(res.loc));
@@ -439,7 +440,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
439440

440441
let range = globals.buffers.offset(BufTy::Base, 1)..globals.buffers.offset(BufTy::Base, 2);
441442
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);
443+
let bst_res = globals.hash.lookup_str(globals.pool, bst_fn, StrIlk::BstFn);
443444

444445
let type_exists = if bst_res.exists {
445446
matches!(
@@ -515,12 +516,12 @@ pub(crate) fn get_bib_command_or_entry_and_process(
515516

516517
let lc_res = if ctx.all_entries {
517518
globals
518-
.pool
519-
.lookup_str_insert(ctx, globals.hash, lc_cite, HashExtra::LcCite(0))?
519+
.hash
520+
.lookup_str_insert(ctx, globals.pool, lc_cite, HashExtra::LcCite(0))?
520521
} else {
521522
globals
522-
.pool
523-
.lookup_str(globals.hash, lc_cite, StrIlk::LcCite)
523+
.hash
524+
.lookup_str(globals.pool, lc_cite, StrIlk::LcCite)
524525
};
525526

526527
let mut res = lc_res;
@@ -546,9 +547,9 @@ pub(crate) fn get_bib_command_or_entry_and_process(
546547
let range = globals.buffers.offset(BufTy::Base, 1)
547548
..globals.buffers.offset(BufTy::Base, 2);
548549
let cite = &globals.buffers.buffer(BufTy::Base)[range];
549-
let uc_res = globals.pool.lookup_str_insert(
550+
let uc_res = globals.hash.lookup_str_insert(
550551
ctx,
551-
globals.hash,
552+
globals.pool,
552553
cite,
553554
HashExtra::Cite(0),
554555
);
@@ -578,8 +579,8 @@ pub(crate) fn get_bib_command_or_entry_and_process(
578579
lc_cite.make_ascii_lowercase();
579580

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

584585
res = lc_res2;
585586

@@ -637,8 +638,8 @@ pub(crate) fn get_bib_command_or_entry_and_process(
637638
[globals.buffers.offset(BufTy::Base, 1)..globals.buffers.offset(BufTy::Base, 2)];
638639
let res =
639640
globals
640-
.pool
641-
.lookup_str_insert(ctx, globals.hash, cite, HashExtra::Cite(0))?;
641+
.hash
642+
.lookup_str_insert(ctx, globals.pool, cite, HashExtra::Cite(0))?;
642643
if res.exists {
643644
hash_cite_confusion(ctx);
644645
return Err(BibtexError::Fatal);
@@ -744,7 +745,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
744745
let bst_fn = &mut globals.buffers.buffer_mut(BufTy::Base)[range];
745746
bst_fn.make_ascii_lowercase();
746747

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

749750
*field_name_loc = res.loc;
750751
if res.exists {

0 commit comments

Comments
 (0)