Skip to content

Commit 98e3b66

Browse files
michielp1807folkertdev
authored andcommitted
ZDICT_analyzePos: use LLIMIT and MINMATCHLENGTH as usize
1 parent b16ec0d commit 98e3b66

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

lib/dictBuilder/zdict.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ unsafe fn ZDICT_count(
142142
}
143143
}
144144

145-
const LLIMIT: core::ffi::c_int = 64;
146-
const MINMATCHLENGTH: core::ffi::c_int = 7;
145+
const LLIMIT: usize = 64;
146+
const MINMATCHLENGTH: usize = 7;
147147
unsafe fn ZDICT_analyzePos(
148148
doneMarks: *mut u8,
149149
suffix: *const core::ffi::c_uint,
@@ -152,11 +152,11 @@ unsafe fn ZDICT_analyzePos(
152152
minRatio: u32,
153153
notificationLevel: u32,
154154
) -> DictItem {
155-
let mut lengthList: [u32; 64] = [0; 64];
156-
let mut cumulLength: [u32; 64] = [0; 64];
157-
let mut savings: [u32; 64] = [0; 64];
155+
let mut lengthList = [0u32; LLIMIT];
156+
let mut cumulLength = [0u32; LLIMIT];
157+
let mut savings = [0u32; LLIMIT];
158158
let b = buffer as *const u8;
159-
let mut maxLength = LLIMIT as size_t;
159+
let mut maxLength = LLIMIT;
160160
let mut pos = *suffix.offset(start as isize) as size_t;
161161
let mut end = start;
162162
let mut solution = DictItem::default();
@@ -196,7 +196,7 @@ unsafe fn ZDICT_analyzePos(
196196
b.add(pos) as *const core::ffi::c_void,
197197
b.offset(*suffix.offset(end as isize) as isize) as *const core::ffi::c_void,
198198
);
199-
if length < MINMATCHLENGTH as size_t {
199+
if length < MINMATCHLENGTH {
200200
break;
201201
}
202202
}
@@ -206,10 +206,10 @@ unsafe fn ZDICT_analyzePos(
206206
b.add(pos) as *const core::ffi::c_void,
207207
b.offset(*suffix.offset(start as isize).sub(1) as isize) as *const core::ffi::c_void,
208208
);
209-
if length_0 >= MINMATCHLENGTH as size_t {
209+
if length_0 >= MINMATCHLENGTH {
210210
start = start.wrapping_sub(1);
211211
}
212-
if length_0 < MINMATCHLENGTH as size_t {
212+
if length_0 < MINMATCHLENGTH {
213213
break;
214214
}
215215
}
@@ -233,7 +233,7 @@ unsafe fn ZDICT_analyzePos(
233233
eprint!(
234234
"found {:>3} matches of length >= {} at pos {:>7} ",
235235
end.wrapping_sub(start),
236-
7,
236+
MINMATCHLENGTH,
237237
pos as core::ffi::c_uint,
238238
);
239239
}
@@ -291,31 +291,28 @@ unsafe fn ZDICT_analyzePos(
291291
b.add(pos) as *const core::ffi::c_void,
292292
b.offset(*suffix.offset(end as isize) as isize) as *const core::ffi::c_void,
293293
);
294-
if length_1 >= LLIMIT as size_t {
295-
length_1 = (LLIMIT - 1) as size_t;
294+
if length_1 >= LLIMIT {
295+
length_1 = LLIMIT - 1;
296296
}
297297
let fresh0 = &mut (*lengthList.as_mut_ptr().add(length_1));
298298
*fresh0 = (*fresh0).wrapping_add(1);
299-
if length_1 < MINMATCHLENGTH as size_t {
299+
if length_1 < MINMATCHLENGTH {
300300
break;
301301
}
302302
}
303-
let mut length_2 = MINMATCHLENGTH as size_t;
304-
while (length_2 >= MINMATCHLENGTH as size_t) as core::ffi::c_int
305-
& (start > 0) as core::ffi::c_int
306-
!= 0
307-
{
303+
let mut length_2 = MINMATCHLENGTH;
304+
while (length_2 >= MINMATCHLENGTH) as core::ffi::c_int & (start > 0) as core::ffi::c_int != 0 {
308305
length_2 = ZDICT_count(
309306
b.add(pos) as *const core::ffi::c_void,
310307
b.offset(*suffix.offset(start.wrapping_sub(1) as isize) as isize)
311308
as *const core::ffi::c_void,
312309
);
313-
if length_2 >= LLIMIT as size_t {
314-
length_2 = (LLIMIT - 1) as size_t;
310+
if length_2 >= LLIMIT {
311+
length_2 = LLIMIT - 1;
315312
}
316313
let fresh1 = &mut (*lengthList.as_mut_ptr().add(length_2));
317314
*fresh1 = (*fresh1).wrapping_add(1);
318-
if length_2 >= MINMATCHLENGTH as size_t {
315+
if length_2 >= MINMATCHLENGTH {
319316
start = start.wrapping_sub(1);
320317
}
321318
}
@@ -350,7 +347,7 @@ unsafe fn ZDICT_analyzePos(
350347
l = l.wrapping_sub(1);
351348
}
352349
maxLength = l as size_t;
353-
if maxLength < MINMATCHLENGTH as size_t {
350+
if maxLength < MINMATCHLENGTH {
354351
return solution;
355352
}
356353
*savings.as_mut_ptr().add(5) = 0;

0 commit comments

Comments
 (0)