Skip to content

Commit 05efe9d

Browse files
committed
Minor cleanups - remove thread locals, improve history, directly import functions
1 parent 1204a2d commit 05efe9d

13 files changed

Lines changed: 86 additions & 272 deletions

File tree

crates/engine_bibtex/src/auxi.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717
scan::Scan,
1818
Bibtex, BibtexError, GlobalItems, StrIlk, StrNumber,
1919
};
20-
use std::{cell::RefCell, ffi::CString, ptr::NonNull};
20+
use std::{ffi::CString, ptr::NonNull};
2121
use tectonic_bridge_core::FileFormat;
2222

2323
const AUX_STACK_SIZE: usize = 20;
@@ -33,7 +33,7 @@ pub(crate) struct AuxData {
3333
}
3434

3535
impl AuxData {
36-
fn new() -> AuxData {
36+
pub fn new() -> AuxData {
3737
AuxData { aux: Vec::new() }
3838
}
3939

@@ -59,18 +59,6 @@ impl AuxData {
5959
}
6060
}
6161

62-
thread_local! {
63-
static AUX: RefCell<AuxData> = RefCell::new(AuxData::new());
64-
}
65-
66-
pub fn reset() {
67-
AUX.with(|aux| *aux.borrow_mut() = AuxData::new());
68-
}
69-
70-
pub(crate) fn with_aux_mut<T>(f: impl FnOnce(&mut AuxData) -> T) -> T {
71-
AUX.with(|aux| f(&mut aux.borrow_mut()))
72-
}
73-
7462
fn aux_bib_data_command(
7563
ctx: &mut Bibtex<'_, '_>,
7664
buffers: &mut GlobalBuffer,

crates/engine_bibtex/src/bibs.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
xbuf::XBuf,
1515
BibNumber, Bibtex, BibtexError, CiteNumber, GlobalItems, HashPointer, StrIlk, StrNumber,
1616
};
17-
use std::{cell::RefCell, ptr::NonNull};
17+
use std::ptr::NonNull;
1818

1919
const MAX_BIB_FILES: usize = 20;
2020

@@ -28,7 +28,7 @@ pub(crate) struct BibData {
2828
}
2929

3030
impl BibData {
31-
fn new() -> BibData {
31+
pub fn new() -> BibData {
3232
BibData {
3333
bib_file: XBuf::new(MAX_BIB_FILES),
3434
bib_list: XBuf::new(MAX_BIB_FILES),
@@ -110,18 +110,6 @@ impl BibData {
110110
}
111111
}
112112

113-
thread_local! {
114-
static BIBS: RefCell<BibData> = RefCell::new(BibData::new());
115-
}
116-
117-
pub(crate) fn with_bibs_mut<T>(f: impl FnOnce(&mut BibData) -> T) -> T {
118-
BIBS.with(|bibs| f(&mut bibs.borrow_mut()))
119-
}
120-
121-
pub fn reset() {
122-
BIBS.with(|bibs| *bibs.borrow_mut() = BibData::new());
123-
}
124-
125113
pub(crate) fn eat_bib_white_space(buffers: &mut GlobalBuffer, bibs: &mut BibData) -> bool {
126114
let mut init = buffers.init(BufTy::Base);
127115
while !Scan::new()

crates/engine_bibtex/src/buffer.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,10 @@ use crate::{
22
xbuf::{SafelyZero, XBuf},
33
ASCIICode, BufPointer,
44
};
5-
use std::{cell::RefCell, slice};
5+
use std::slice;
66

77
pub(crate) const BUF_SIZE: usize = 20000;
88

9-
thread_local! {
10-
static GLOBAL_BUFFERS: RefCell<GlobalBuffer> = RefCell::new(GlobalBuffer::new());
11-
}
12-
13-
pub(crate) fn reset() {
14-
GLOBAL_BUFFERS.with(|cell| *cell.borrow_mut() = GlobalBuffer::new());
15-
}
16-
17-
pub(crate) fn with_buffers_mut<T>(f: impl FnOnce(&mut GlobalBuffer) -> T) -> T {
18-
GLOBAL_BUFFERS.with(|buffers| f(&mut buffers.borrow_mut()))
19-
}
20-
219
struct Buffer<T: SafelyZero + 'static, const N: usize> {
2210
ptr: XBuf<T>,
2311
/// Stateful offsets into the buffer

crates/engine_bibtex/src/cite.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
entries::EntryData, hash::HashData, other::OtherData, pool::StringPool, xbuf::XBuf, CiteNumber,
33
FindCiteLocs, HashPointer, StrIlk, StrNumber,
44
};
5-
use std::{cell::RefCell, cmp::Ordering, ops::IndexMut};
5+
use std::{cmp::Ordering, ops::IndexMut};
66

77
pub(crate) const MAX_CITES: usize = 750;
88

@@ -20,7 +20,7 @@ pub(crate) struct CiteInfo {
2020
}
2121

2222
impl CiteInfo {
23-
fn new() -> CiteInfo {
23+
pub fn new() -> CiteInfo {
2424
CiteInfo {
2525
cite_list: XBuf::new(MAX_CITES),
2626
cite_info: XBuf::new(MAX_CITES),
@@ -125,18 +125,6 @@ impl CiteInfo {
125125
}
126126
}
127127

128-
thread_local! {
129-
static CITE_INFO: RefCell<CiteInfo> = RefCell::new(CiteInfo::new());
130-
}
131-
132-
pub fn reset() {
133-
CITE_INFO.with(|ci| *ci.borrow_mut() = CiteInfo::new());
134-
}
135-
136-
pub(crate) fn with_cites_mut<T>(f: impl FnOnce(&mut CiteInfo) -> T) -> T {
137-
CITE_INFO.with(|ci| f(&mut ci.borrow_mut()))
138-
}
139-
140128
fn less_than(entries: &EntryData, arg1: &CiteNumber, arg2: &CiteNumber) -> Ordering {
141129
let ptr1 = arg1 * entries.num_ent_strs() + entries.sort_key_num();
142130
let ptr2 = arg2 * entries.num_ent_strs() + entries.sort_key_num();

crates/engine_bibtex/src/entries.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::{cite::CiteInfo, xbuf::XBuf, ASCIICode};
2-
use std::cell::RefCell;
32

43
pub(crate) const ENT_STR_SIZE: usize = 250;
54

@@ -12,7 +11,7 @@ pub(crate) struct EntryData {
1211
}
1312

1413
impl EntryData {
15-
fn new() -> EntryData {
14+
pub fn new() -> EntryData {
1615
EntryData {
1716
num_entry_ints: 0,
1817
num_entry_strs: 0,
@@ -83,15 +82,3 @@ impl EntryData {
8382
self.entry_strs = Some(new_buf);
8483
}
8584
}
86-
87-
thread_local! {
88-
static ENTRIES: RefCell<EntryData> = RefCell::new(EntryData::new());
89-
}
90-
91-
pub fn reset() {
92-
ENTRIES.with(|entries| *entries.borrow_mut() = EntryData::new());
93-
}
94-
95-
pub(crate) fn with_entries_mut<T>(f: impl FnOnce(&mut EntryData) -> T) -> T {
96-
ENTRIES.with(|entries| f(&mut entries.borrow_mut()))
97-
}

crates/engine_bibtex/src/global.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::{xbuf::XBuf, ASCIICode, StrNumber};
2-
use std::cell::RefCell;
32

43
const MAX_GLOB_STRS: usize = 10;
54
pub(crate) const GLOB_STR_SIZE: usize = 20000;
@@ -12,7 +11,7 @@ pub(crate) struct GlobalData {
1211
}
1312

1413
impl GlobalData {
15-
fn new() -> GlobalData {
14+
pub fn new() -> GlobalData {
1615
GlobalData {
1716
glb_bib_str_ptr: XBuf::new(MAX_GLOB_STRS),
1817
global_strs: XBuf::new((GLOB_STR_SIZE + 1) * MAX_GLOB_STRS),
@@ -58,15 +57,3 @@ impl GlobalData {
5857
self.glb_bib_str_ptr.len()
5958
}
6059
}
61-
62-
thread_local! {
63-
static GLOBALS: RefCell<GlobalData> = RefCell::new(GlobalData::new());
64-
}
65-
66-
pub fn reset() {
67-
GLOBALS.with(|globals| *globals.borrow_mut() = GlobalData::new());
68-
}
69-
70-
pub(crate) fn with_globals_mut<T>(f: impl FnOnce(&mut GlobalData) -> T) -> T {
71-
GLOBALS.with(|globals| f(&mut globals.borrow_mut()))
72-
}

crates/engine_bibtex/src/hash.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::{
33
xbuf::{SafelyZero, XBuf},
44
HashPointer, StrIlk, StrNumber,
55
};
6-
use std::cell::RefCell;
76

87
pub(crate) const HASH_BASE: usize = 1;
98
pub(crate) const HASH_SIZE: usize = if pool::MAX_STRINGS > 5000 {
@@ -161,15 +160,3 @@ impl HashData {
161160
self.ilk_info[pos] = info;
162161
}
163162
}
164-
165-
thread_local! {
166-
static HASHES: RefCell<HashData> = RefCell::new(HashData::new());
167-
}
168-
169-
pub fn reset() {
170-
HASHES.with(|hash| *hash.borrow_mut() = HashData::new());
171-
}
172-
173-
pub(crate) fn with_hash_mut<T>(f: impl FnOnce(&mut HashData) -> T) -> T {
174-
HASHES.with(|h| f(&mut h.borrow_mut()))
175-
}

crates/engine_bibtex/src/history.rs

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,17 @@ use std::cell::Cell;
33
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
44
pub enum History {
55
Spotless,
6-
WarningIssued,
7-
ErrorIssued,
6+
WarningIssued(u32),
7+
ErrorIssued(u32),
88
FatalError,
99
}
1010

1111
thread_local! {
1212
static HISTORY: Cell<History> = Cell::new(History::Spotless);
13-
static ERR_COUNT: Cell<u32> = Cell::new(0);
1413
}
1514

1615
pub(crate) fn reset() {
1716
HISTORY.with(|cell| cell.set(History::Spotless));
18-
ERR_COUNT.with(|cell| cell.set(0));
19-
}
20-
21-
fn get_err() -> u32 {
22-
ERR_COUNT.with(|e| e.get())
23-
}
24-
25-
fn set_err(f: impl FnOnce(u32) -> u32) {
26-
ERR_COUNT.with(|e| e.set(f(e.get())))
2717
}
2818

2919
pub(crate) fn get_history() -> History {
@@ -35,28 +25,21 @@ pub(crate) fn set_history(hist: History) {
3525
}
3626

3727
pub(crate) fn mark_warning() {
38-
let history = get_history();
39-
if history == History::WarningIssued {
40-
set_err(|e| e + 1);
41-
} else if history == History::Spotless {
42-
set_history(History::WarningIssued);
43-
set_err(|_| 1);
28+
match get_history() {
29+
History::WarningIssued(cur) => set_history(History::WarningIssued(cur + 1)),
30+
History::Spotless => set_history(History::WarningIssued(1)),
31+
_ => (),
4432
}
4533
}
4634

4735
pub(crate) fn mark_error() {
48-
if get_history() < History::ErrorIssued {
49-
set_history(History::ErrorIssued);
50-
set_err(|_| 1);
51-
} else {
52-
set_err(|e| e + 1);
36+
match get_history() {
37+
History::Spotless | History::WarningIssued(_) => set_history(History::ErrorIssued(1)),
38+
History::ErrorIssued(cur) => set_history(History::ErrorIssued(cur + 1)),
39+
_ => (),
5340
}
5441
}
5542

5643
pub fn mark_fatal() {
5744
set_history(History::FatalError);
5845
}
59-
60-
pub fn err_count() -> u32 {
61-
get_err()
62-
}

0 commit comments

Comments
 (0)