Skip to content

Commit de34c24

Browse files
committed
Minor cleanups to impl
1 parent f8a2e86 commit de34c24

1 file changed

Lines changed: 34 additions & 30 deletions

File tree

crates/engine_bibtex/src/hash.rs

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -122,31 +122,38 @@ pub(crate) enum BstFn {
122122
StrGlbl(usize),
123123
}
124124

125-
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
125+
#[repr(u16)]
126+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
126127
pub enum StrIlk {
127-
Text,
128-
Integer,
129-
AuxCommand,
130-
AuxFile,
131-
BstCommand,
132-
BstFile,
133-
BibFile,
134-
FileExt,
135-
Cite,
136-
LcCite,
137-
BstFn,
138-
BibCommand,
139-
Macro,
140-
ControlSeq,
128+
Text = 0x0001,
129+
Integer = 0x0002,
130+
AuxCommand = 0x0004,
131+
AuxFile = 0x0008,
132+
BstCommand = 0x0010,
133+
BstFile = 0x0020,
134+
BibFile = 0x0040,
135+
FileExt = 0x0080,
136+
Cite = 0x0100,
137+
LcCite = 0x0200,
138+
BstFn = 0x0400,
139+
BibCommand = 0x0800,
140+
Macro = 0x1000,
141+
ControlSeq = 0x2000,
141142
}
142143

143144
pub trait Ilk {
144145
type Extra;
145146
fn ilk() -> StrIlk;
146147
fn get(slot: &ExtraSlot) -> &Self::Extra;
147-
fn insert(slot: &mut ExtraSlot, extra: Self::Extra) {
148+
149+
fn set(slot: &mut ExtraSlot, extra: Self::Extra) {
148150
let _ = (slot, extra);
149151
}
152+
153+
fn insert(slot: &mut ExtraSlot, extra: Self::Extra) {
154+
Self::set(slot, extra);
155+
slot.set_present(Self::ilk());
156+
}
150157
}
151158

152159
pub struct Text;
@@ -174,7 +181,7 @@ impl Ilk for Integer {
174181
&slot.data.0
175182
}
176183

177-
fn insert(slot: &mut ExtraSlot, extra: Self::Extra) {
184+
fn set(slot: &mut ExtraSlot, extra: Self::Extra) {
178185
slot.data.0 = extra;
179186
}
180187
}
@@ -190,7 +197,7 @@ impl Ilk for AuxCommand {
190197
&slot.data.1
191198
}
192199

193-
fn insert(slot: &mut ExtraSlot, extra: Self::Extra) {
200+
fn set(slot: &mut ExtraSlot, extra: Self::Extra) {
194201
slot.data.1 = extra;
195202
}
196203
}
@@ -219,7 +226,7 @@ impl Ilk for BstCommand {
219226
&slot.data.2
220227
}
221228

222-
fn insert(slot: &mut ExtraSlot, extra: Self::Extra) {
229+
fn set(slot: &mut ExtraSlot, extra: Self::Extra) {
223230
slot.data.2 = extra;
224231
}
225232
}
@@ -275,7 +282,7 @@ impl Ilk for Cite {
275282
&slot.data.3
276283
}
277284

278-
fn insert(slot: &mut ExtraSlot, extra: Self::Extra) {
285+
fn set(slot: &mut ExtraSlot, extra: Self::Extra) {
279286
slot.data.3 = extra;
280287
}
281288
}
@@ -292,7 +299,7 @@ impl Ilk for LcCite {
292299
&slot.data.4
293300
}
294301

295-
fn insert(slot: &mut ExtraSlot, extra: Self::Extra) {
302+
fn set(slot: &mut ExtraSlot, extra: Self::Extra) {
296303
slot.data.4 = extra;
297304
}
298305
}
@@ -308,7 +315,7 @@ impl Ilk for BstFn {
308315
&slot.data.5
309316
}
310317

311-
fn insert(slot: &mut ExtraSlot, extra: Self::Extra) {
318+
fn set(slot: &mut ExtraSlot, extra: Self::Extra) {
312319
slot.data.5 = extra;
313320
}
314321
}
@@ -324,7 +331,7 @@ impl Ilk for BibCommand {
324331
&slot.data.6
325332
}
326333

327-
fn insert(slot: &mut ExtraSlot, extra: Self::Extra) {
334+
fn set(slot: &mut ExtraSlot, extra: Self::Extra) {
328335
slot.data.6 = extra;
329336
}
330337
}
@@ -341,7 +348,7 @@ impl Ilk for Macro {
341348
&slot.data.7
342349
}
343350

344-
fn insert(slot: &mut ExtraSlot, extra: Self::Extra) {
351+
fn set(slot: &mut ExtraSlot, extra: Self::Extra) {
345352
slot.data.7 = extra;
346353
}
347354
}
@@ -357,7 +364,7 @@ impl Ilk for ControlSeq {
357364
&slot.data.8
358365
}
359366

360-
fn insert(slot: &mut ExtraSlot, extra: Self::Extra) {
367+
fn set(slot: &mut ExtraSlot, extra: Self::Extra) {
361368
slot.data.8 = extra;
362369
}
363370
}
@@ -388,12 +395,12 @@ impl ExtraSlot {
388395

389396
fn contains(&self, ilk: StrIlk) -> bool {
390397
let idx = ilk as u16;
391-
(self.exists & (1 << idx)) != 0
398+
(self.exists & idx) != 0
392399
}
393400

394401
fn set_present(&mut self, ilk: StrIlk) {
395402
let idx = ilk as u16;
396-
self.exists |= 1 << idx;
403+
self.exists |= idx;
397404
}
398405
}
399406

@@ -511,7 +518,6 @@ impl HashData {
511518
pub fn set_extra<T: Ilk>(&mut self, pos: HashPointer<T>, val: T::Extra) {
512519
let node = self.data.get_index_mut2(pos.0).unwrap();
513520
T::insert(&mut node.extra, val);
514-
node.extra.set_present(T::ilk());
515521
}
516522

517523
pub fn lookup_str<T: Ilk>(&self, pool: &StringPool, str: &[u8]) -> Option<HashPointer<T>> {
@@ -549,7 +555,6 @@ impl HashData {
549555
}
550556
} else {
551557
T::insert(&mut node.extra, extra);
552-
node.extra.set_present(T::ilk());
553558
LookupRes {
554559
exists: false,
555560
loc: HashPointer(idx, PhantomData),
@@ -560,7 +565,6 @@ impl HashData {
560565
let text = pool.add_string(str);
561566
let mut slot = ExtraSlot::new();
562567
T::insert(&mut slot, extra);
563-
slot.set_present(T::ilk());
564568
let (idx, _) = self.data.insert_full(Node {
565569
hash_val,
566570
text,

0 commit comments

Comments
 (0)