Skip to content

Commit e2e887d

Browse files
committed
Remove text method - closer to HashData just being a slotmap with lookup
1 parent 0ce7e45 commit e2e887d

9 files changed

Lines changed: 76 additions & 80 deletions

File tree

crates/engine_bibtex/src/auxi.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,24 +109,24 @@ fn aux_bib_data_command(
109109
let res = hash.lookup_str_insert(pool, file, HashExtra::BibFile);
110110
if res.exists {
111111
ctx.write_logs("This database file appears more than once: ");
112-
print_bib_name(ctx, pool, hash.text(res.loc))?;
112+
print_bib_name(ctx, pool, hash.get(res.loc).text())?;
113113
aux_err_print(ctx, buffers, aux, pool)?;
114114
return Ok(());
115115
}
116116

117-
let name = pool.get_str(hash.text(res.loc));
117+
let name = pool.get_str(hash.get(res.loc).text());
118118
let fname = CString::new(name).unwrap();
119119
let bib_in = PeekableInput::open(ctx, &fname, FileFormat::Bib);
120120
match bib_in {
121121
Err(_) => {
122122
ctx.write_logs("I couldn't open database file ");
123-
print_bib_name(ctx, pool, hash.text(res.loc))?;
123+
print_bib_name(ctx, pool, hash.get(res.loc).text())?;
124124
aux_err_print(ctx, buffers, aux, pool)?;
125125
return Ok(());
126126
}
127127
Ok(file) => {
128128
bibs.push_file(File {
129-
name: hash.text(res.loc),
129+
name: hash.get(res.loc).text(),
130130
file,
131131
line: 0,
132132
});
@@ -184,20 +184,20 @@ fn aux_bib_style_command(
184184
return Err(BibtexError::Fatal);
185185
}
186186

187-
let name = pool.get_str(hash.text(res.loc));
187+
let name = pool.get_str(hash.get(res.loc).text());
188188
let fname = CString::new(name).unwrap();
189189
let bst_file = PeekableInput::open(ctx, &fname, FileFormat::Bst);
190190
match bst_file {
191191
Err(_) => {
192192
ctx.write_logs("I couldn't open style file ");
193-
print_bst_name(ctx, pool, hash.text(res.loc))?;
193+
print_bst_name(ctx, pool, hash.get(res.loc).text())?;
194194
ctx.bst = None;
195195
aux_err_print(ctx, buffers, aux, pool)?;
196196
return Ok(());
197197
}
198198
Ok(file) => {
199199
ctx.bst = Some(File {
200-
name: hash.text(res.loc),
200+
name: hash.get(res.loc).text(),
201201
file,
202202
line: 0,
203203
});
@@ -279,15 +279,15 @@ fn aux_citation_command(
279279

280280
let lc_res = hash.lookup_str_insert(pool, lc_cite, HashExtra::LcCite(HashPointer::default()));
281281
if lc_res.exists {
282-
let &HashExtra::LcCite(cite_loc) = hash.node(lc_res.loc).extra() else {
282+
let &HashExtra::LcCite(cite_loc) = hash.get(lc_res.loc).extra() else {
283283
panic!("LcCite lookup didn't have LcCite extra");
284284
};
285285

286286
let cite = &buffers.buffer(BufTy::Base)
287287
[buffers.offset(BufTy::Base, 1)..buffers.offset(BufTy::Base, 2)];
288288
let uc_res = hash.lookup_str(pool, cite, StrIlk::Cite);
289289
if uc_res.is_none() {
290-
let &HashExtra::Cite(cite) = hash.node(cite_loc).extra() else {
290+
let &HashExtra::Cite(cite) = hash.get(cite_loc).extra() else {
291291
panic!("LcCite location didn't have a Cite extra");
292292
};
293293

@@ -312,9 +312,9 @@ fn aux_citation_command(
312312
cites.grow();
313313
}
314314

315-
cites.set_cite(cites.ptr(), hash.text(uc_res.loc));
316-
*hash.node_mut(uc_res.loc).extra_mut() = HashExtra::Cite(cites.ptr());
317-
*hash.node_mut(lc_res.loc).extra_mut() = HashExtra::LcCite(uc_res.loc);
315+
cites.set_cite(cites.ptr(), hash.get(uc_res.loc).text());
316+
*hash.get_mut(uc_res.loc).extra_mut() = HashExtra::Cite(cites.ptr());
317+
*hash.get_mut(lc_res.loc).extra_mut() = HashExtra::LcCite(uc_res.loc);
318318
cites.set_ptr(cites.ptr() + 1);
319319
}
320320
}
@@ -379,24 +379,24 @@ fn aux_input_command(
379379
let res = hash.lookup_str_insert(pool, file, HashExtra::AuxFile);
380380
if res.exists {
381381
ctx.write_logs("Already encountered file ");
382-
print_aux_name(ctx, pool, hash.text(res.loc))?;
382+
print_aux_name(ctx, pool, hash.get(res.loc).text())?;
383383
aux_err_print(ctx, buffers, aux, pool)?;
384384
return Ok(());
385385
}
386386

387-
let name = pool.get_str(hash.text(res.loc));
387+
let name = pool.get_str(hash.get(res.loc).text());
388388
let fname = CString::new(name).unwrap();
389389
let file = PeekableInput::open(ctx, &fname, FileFormat::Tex);
390390
match file {
391391
Err(_) => {
392392
ctx.write_logs("I couldn't open auxiliary file ");
393-
print_aux_name(ctx, pool, hash.text(res.loc))?;
393+
print_aux_name(ctx, pool, hash.get(res.loc).text())?;
394394
aux_err_print(ctx, buffers, aux, pool)?;
395395
return Ok(());
396396
}
397397
Ok(file) => {
398398
aux.push_file(File {
399-
name: hash.text(res.loc),
399+
name: hash.get(res.loc).text(),
400400
file,
401401
line: 0,
402402
});
@@ -426,7 +426,7 @@ pub(crate) fn get_aux_command_and_process(
426426
.lookup_str(globals.pool, line, StrIlk::AuxCommand);
427427

428428
if let Some(loc) = res {
429-
let &HashExtra::AuxCommand(cmd) = globals.hash.node(loc).extra() else {
429+
let &HashExtra::AuxCommand(cmd) = globals.hash.get(loc).extra() else {
430430
panic!("AuxCommand lookup didn't have AuxCommand extra");
431431
};
432432

crates/engine_bibtex/src/bibs.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
198198
let mut lc_cite_loc = HashPointer::default();
199199

200200
if let Some(loc) = res {
201-
let &HashExtra::BibCommand(cmd) = globals.hash.node(loc).extra() else {
201+
let &HashExtra::BibCommand(cmd) = globals.hash.get(loc).extra() else {
202202
panic!("BibCommand lookup didn't have BibCommand extra");
203203
};
204204

@@ -358,7 +358,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
358358
HashExtra::Macro(StrNumber::default()),
359359
);
360360
// TODO: Insert overwriting?
361-
*globals.hash.node_mut(res.loc).extra_mut() = HashExtra::Macro(globals.hash.text(res.loc));
361+
*globals.hash.get_mut(res.loc).extra_mut() = HashExtra::Macro(globals.hash.get(res.loc).text());
362362
*cur_macro_loc = res.loc;
363363

364364
if !eat_bib_white_space(ctx, globals.buffers, globals.bibs) {
@@ -444,7 +444,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
444444
.lookup_str(globals.pool, bst_fn, StrIlk::BstFn)
445445
.filter(|&loc| {
446446
matches!(
447-
globals.hash.node(loc).extra(),
447+
globals.hash.get(loc).extra(),
448448
HashExtra::BstFn(BstFn::Wizard(_))
449449
)
450450
});
@@ -534,10 +534,10 @@ pub(crate) fn get_bib_command_or_entry_and_process(
534534
// TODO: Improve this tangled control flow
535535
let mut inner = || {
536536
if lc_res.exists {
537-
let &HashExtra::LcCite(cite_loc) = globals.hash.node(lc_res.loc).extra() else {
537+
let &HashExtra::LcCite(cite_loc) = globals.hash.get(lc_res.loc).extra() else {
538538
panic!("LcCite lookup didn't have LcCite extra");
539539
};
540-
let &HashExtra::Cite(cite) = globals.hash.node(cite_loc).extra() else {
540+
let &HashExtra::Cite(cite) = globals.hash.get(cite_loc).extra() else {
541541
panic!("LcCite location didn't have Cite extra");
542542
};
543543

@@ -561,11 +561,11 @@ pub(crate) fn get_bib_command_or_entry_and_process(
561561
res = uc_res;
562562

563563
if !uc_res.exists {
564-
*globals.hash.node_mut(lc_res.loc).extra_mut() = HashExtra::LcCite(uc_res.loc);
565-
*globals.hash.node_mut(uc_res.loc).extra_mut() = HashExtra::Cite(entry_ptr);
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);
566566
globals
567567
.cites
568-
.set_cite(entry_ptr, globals.hash.text(uc_res.loc));
568+
.set_cite(entry_ptr, globals.hash.get(uc_res.loc).text());
569569
res.exists = true;
570570
}
571571
}
@@ -625,7 +625,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
625625
if res.exists {
626626
if globals.cites.entry_ptr() >= globals.cites.all_marker() {
627627
globals.cites.set_exists(globals.cites.entry_ptr(), true);
628-
let &HashExtra::LcCite(cite_loc) = globals.hash.node(lc_res.loc).extra() else {
628+
let &HashExtra::LcCite(cite_loc) = globals.hash.get(lc_res.loc).extra() else {
629629
panic!("LcCite lookup didn't have LcCite extra");
630630
};
631631
globals.cites.set_entry_ptr(globals.cites.ptr());
@@ -754,7 +754,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
754754
match res {
755755
Some(loc)
756756
if matches!(
757-
globals.hash.node(loc).extra(),
757+
globals.hash.get(loc).extra(),
758758
HashExtra::BstFn(BstFn::Field(_))
759759
) =>
760760
{

crates/engine_bibtex/src/bst.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ fn bst_function_command(
266266
return Ok(());
267267
}
268268

269-
if globals.hash.text(res.loc) == ctx.s_default {
269+
if globals.hash.get(res.loc).text() == ctx.s_default {
270270
ctx.default = res.loc;
271271
}
272272

@@ -406,7 +406,7 @@ fn bst_macro_command(
406406
return Ok(());
407407
}
408408
// This is always unused if the macro is successfully defined, but appears to be a fallback for invalid macros.
409-
*globals.hash.node_mut(res.loc).extra_mut() = HashExtra::Macro(globals.hash.text(res.loc));
409+
*globals.hash.get_mut(res.loc).extra_mut() = HashExtra::Macro(globals.hash.get(res.loc).text());
410410

411411
eat_bst_white!(ctx, globals, "macro");
412412
bst_brace!('}', ctx, globals, "macro");
@@ -440,7 +440,7 @@ fn bst_macro_command(
440440
.hash
441441
.lookup_str_insert(globals.pool, text, HashExtra::Text);
442442

443-
*globals.hash.node_mut(res.loc).extra_mut() = HashExtra::Macro(globals.hash.text(res2.loc));
443+
*globals.hash.get_mut(res.loc).extra_mut() = HashExtra::Macro(globals.hash.get(res2.loc).text());
444444
globals
445445
.buffers
446446
.set_offset(BufTy::Base, 2, globals.buffers.offset(BufTy::Base, 2) + 1);
@@ -559,15 +559,15 @@ fn bst_read_command(
559559
);
560560

561561
if let Some(lc_loc) = find.lc_cite {
562-
let &HashExtra::LcCite(cite_loc) = globals.hash.node(lc_loc).extra() else {
562+
let &HashExtra::LcCite(cite_loc) = globals.hash.get(lc_loc).extra() else {
563563
panic!("LcCite lookup didn't have LcCite extra");
564564
};
565565
globals
566566
.other
567-
.set_field(field_ptr, globals.hash.text(cite_loc));
567+
.set_field(field_ptr, globals.hash.get(cite_loc).text());
568568

569569
let field_start = cite_ptr * globals.other.num_fields();
570-
let &HashExtra::Cite(cite) = globals.hash.node(cite_loc).extra() else {
570+
let &HashExtra::Cite(cite) = globals.hash.get(cite_loc).extra() else {
571571
panic!("LcCite location didn't have Cite extra");
572572
};
573573
let mut parent =
@@ -594,15 +594,15 @@ fn bst_read_command(
594594
);
595595

596596
if let Some(lc_loc) = find.lc_cite {
597-
let &HashExtra::LcCite(cite_loc) = globals.hash.node(lc_loc).extra() else {
597+
let &HashExtra::LcCite(cite_loc) = globals.hash.get(lc_loc).extra() else {
598598
panic!("LcCite lookup didn't have LcCite extra");
599599
};
600600
if find.cite != Some(cite_loc) {
601601
hash_cite_confusion(ctx);
602602
return Err(BibtexError::Fatal);
603603
}
604604

605-
let &HashExtra::Cite(cite) = globals.hash.node(cite_loc).extra() else {
605+
let &HashExtra::Cite(cite) = globals.hash.get(cite_loc).extra() else {
606606
panic!("Cite lookup didn't have Cite extra");
607607
};
608608
let cite_parent_ptr = cite;
@@ -692,15 +692,15 @@ fn bst_read_command(
692692
}
693693
};
694694

695-
let &HashExtra::LcCite(cite_loc) = globals.hash.node(lc_loc).extra() else {
695+
let &HashExtra::LcCite(cite_loc) = globals.hash.get(lc_loc).extra() else {
696696
panic!("LcCite lookup didn't have LcCite extra");
697697
};
698698
if find.cite.is_none_or(|loc| loc != cite_loc) {
699699
hash_cite_confusion(ctx);
700700
return Err(BibtexError::Fatal);
701701
}
702702

703-
*globals.hash.node_mut(cite_loc).extra_mut() = HashExtra::Cite(ctx.cite_xptr);
703+
*globals.hash.get_mut(cite_loc).extra_mut() = HashExtra::Cite(ctx.cite_xptr);
704704

705705
let start = ctx.cite_xptr * globals.other.num_fields();
706706
let end = start + globals.other.num_fields();
@@ -877,7 +877,7 @@ fn bad_argument_token(
877877

878878
match res {
879879
Some(loc) => {
880-
if let HashExtra::BstFn(BstFn::Builtin(_) | BstFn::Wizard(_)) = hash.node(loc).extra() {
880+
if let HashExtra::BstFn(BstFn::Builtin(_) | BstFn::Wizard(_)) = hash.get(loc).extra() {
881881
Ok(Some(loc))
882882
} else {
883883
print_a_token(ctx, buffers);
@@ -930,7 +930,7 @@ pub(crate) fn get_bst_command_and_process(
930930
}
931931
};
932932

933-
let HashExtra::BstCommand(cmd) = globals.hash.node(loc).extra() else {
933+
let HashExtra::BstCommand(cmd) = globals.hash.get(loc).extra() else {
934934
panic!("BstCommand lookup didn't have BstCommand extra");
935935
};
936936

crates/engine_bibtex/src/cite.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ pub(crate) fn add_database_cite(
155155
}
156156
other.check_field_overflow(other.num_fields() * (new_cite + 1));
157157

158-
cites.set_cite(new_cite, hash.text(cite_loc));
159-
*hash.node_mut(cite_loc).extra_mut() = HashExtra::Cite(new_cite);
160-
*hash.node_mut(lc_cite_loc).extra_mut() = HashExtra::LcCite(cite_loc);
158+
cites.set_cite(new_cite, hash.get(cite_loc).text());
159+
*hash.get_mut(cite_loc).extra_mut() = HashExtra::Cite(new_cite);
160+
*hash.get_mut(lc_cite_loc).extra_mut() = HashExtra::LcCite(cite_loc);
161161
new_cite + 1
162162
}
163163

0 commit comments

Comments
 (0)