Skip to content

Commit 2739a90

Browse files
michielp1807folkertdev
authored andcommitted
ZDICT_trainBuffer_legacy: make doneMarks a vec
1 parent c35d191 commit 2739a90

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

lib/dictBuilder/zdict.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ unsafe fn ZDICT_count(
149149
const LLIMIT: usize = 64;
150150
const MINMATCHLENGTH: usize = 7;
151151
unsafe fn ZDICT_analyzePos(
152-
doneMarks: *mut u8,
152+
doneMarks: &mut [u8],
153153
suffix_slice: &[u32],
154154
mut start: u32,
155155
buffer: *const core::ffi::c_void,
@@ -174,7 +174,7 @@ unsafe fn ZDICT_analyzePos(
174174
let mut pos = suffix(start as usize) as size_t;
175175
let mut end = start;
176176
let mut solution = DictItem::default();
177-
*doneMarks.add(pos) = 1;
177+
doneMarks[pos] = 1;
178178
if MEM_read16(b.add(pos) as *const core::ffi::c_void) as core::ffi::c_int
179179
== MEM_read16(b.add(pos).add(2) as *const core::ffi::c_void) as core::ffi::c_int
180180
|| MEM_read16(b.add(pos).add(1) as *const core::ffi::c_void) as core::ffi::c_int
@@ -198,7 +198,7 @@ unsafe fn ZDICT_analyzePos(
198198
}
199199
u = 1;
200200
while u < patternEnd {
201-
*doneMarks.add(pos.wrapping_add(u as size_t)) = 1;
201+
doneMarks[pos.wrapping_add(u as size_t)] = 1;
202202
u = u.wrapping_add(1);
203203
}
204204
return solution;
@@ -231,7 +231,7 @@ unsafe fn ZDICT_analyzePos(
231231
let mut idx: u32 = 0;
232232
idx = start;
233233
while idx < end {
234-
*doneMarks.offset(suffix(idx as usize) as isize) = 1;
234+
doneMarks[suffix(idx as usize) as usize] = 1;
235235
idx = idx.wrapping_add(1);
236236
}
237237
return solution;
@@ -402,7 +402,7 @@ unsafe fn ZDICT_analyzePos(
402402
pEnd = testedPos.wrapping_add(length_3);
403403
p = testedPos;
404404
while p < pEnd {
405-
*doneMarks.offset(p as isize) = 1;
405+
doneMarks[p as usize] = 1;
406406
p = p.wrapping_add(1);
407407
}
408408
id_0 = id_0.wrapping_add(1);
@@ -593,11 +593,6 @@ unsafe fn ZDICT_trainBuffer_legacy(
593593
mut minRatio: core::ffi::c_uint,
594594
notificationLevel: u32,
595595
) -> size_t {
596-
let doneMarks = malloc(
597-
bufferSize
598-
.wrapping_add(16)
599-
.wrapping_mul(::core::mem::size_of::<u8>()),
600-
) as *mut u8;
601596
let filePos =
602597
malloc((nbFiles as size_t).wrapping_mul(::core::mem::size_of::<u32>())) as *mut u32;
603598
let mut result = 0;
@@ -608,13 +603,12 @@ unsafe fn ZDICT_trainBuffer_legacy(
608603
if notificationLevel >= 2 {
609604
eprintln!("\r{:70 }\r", ""); // clean display line
610605
}
611-
if doneMarks.is_null() || filePos.is_null() {
606+
if filePos.is_null() {
612607
result = Error::memory_allocation.to_error_code();
613608
} else {
614609
if minRatio < MINRATIO {
615610
minRatio = MINRATIO;
616611
}
617-
core::ptr::write_bytes(doneMarks, 0, bufferSize.wrapping_add(16));
618612

619613
// limit sample set size (divsufsort limitation)
620614
if bufferSize > ZDICT_MAX_SAMPLES_SIZE && notificationLevel >= 3 {
@@ -667,15 +661,16 @@ unsafe fn ZDICT_trainBuffer_legacy(
667661
eprintln!("minimum ratio : {} ", minRatio);
668662
}
669663

664+
let mut doneMarks = vec![0u8; bufferSize + 16];
670665
let mut cursor = 0usize;
671666
while cursor < bufferSize {
672-
if *doneMarks.add(cursor) != 0 {
667+
if doneMarks[cursor] != 0 {
673668
cursor += 1;
674669
continue;
675670
}
676671

677672
let solution = ZDICT_analyzePos(
678-
doneMarks,
673+
&mut doneMarks,
679674
&suffix,
680675
reverseSuffix[cursor],
681676
buffer,
@@ -701,7 +696,6 @@ unsafe fn ZDICT_trainBuffer_legacy(
701696
}
702697
}
703698
}
704-
free(doneMarks as *mut core::ffi::c_void);
705699
free(filePos as *mut core::ffi::c_void);
706700
result
707701
}

0 commit comments

Comments
 (0)