Skip to content

Commit b16ec0d

Browse files
michielp1807folkertdev
authored andcommitted
ZDICT_initDictItem: make safe and implement directly on DictItem
1 parent 36cd7fa commit b16ec0d

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/dictBuilder/zdict.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ struct DictItem {
5050
savings: u32,
5151
}
5252

53+
impl DictItem {
54+
fn init(&mut self) {
55+
self.pos = 1;
56+
self.length = 0;
57+
self.savings = -1i32 as u32;
58+
}
59+
}
60+
5361
const MINRATIO: core::ffi::c_int = 4;
5462
const ZDICT_MAX_SAMPLES_SIZE: core::ffi::c_uint = (2000) << 20;
5563
#[expect(deprecated)]
@@ -134,12 +142,6 @@ unsafe fn ZDICT_count(
134142
}
135143
}
136144

137-
unsafe fn ZDICT_initDictItem(d: *mut DictItem) {
138-
(*d).pos = 1;
139-
(*d).length = 0;
140-
(*d).savings = -(1 as core::ffi::c_int) as u32;
141-
}
142-
143145
const LLIMIT: core::ffi::c_int = 64;
144146
const MINMATCHLENGTH: core::ffi::c_int = 7;
145147
unsafe fn ZDICT_analyzePos(
@@ -1335,7 +1337,7 @@ unsafe fn ZDICT_trainFromBuffer_unsafe_legacy(
13351337
free(dictList as *mut core::ffi::c_void);
13361338
return Error::dictionaryCreation_failed.to_error_code();
13371339
}
1338-
ZDICT_initDictItem(dictList);
1340+
dictList.as_mut().unwrap().init();
13391341
ZDICT_trainBuffer_legacy(
13401342
dictList,
13411343
dictListSize,

0 commit comments

Comments
 (0)