Skip to content

Commit 3d3e844

Browse files
michielp1807folkertdev
authored andcommitted
ZDICT_trainFromBuffer_unsafe_legacy: clean up loops
1 parent 320c47a commit 3d3e844

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

lib/dictBuilder/zdict.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,6 @@ unsafe fn ZDICT_trainFromBuffer_unsafe_legacy(
13751375
};
13761376
let targetDictSize = maxDictSize;
13771377
let samplesBuffSize = samplesSizes.iter().sum();
1378-
let mut dictSize = 0;
13791378
let notificationLevel = params.zParams.notificationLevel;
13801379

13811380
// checks
@@ -1411,15 +1410,13 @@ unsafe fn ZDICT_trainFromBuffer_unsafe_legacy(
14111410
if params.zParams.notificationLevel >= 3 {
14121411
let nb = Ord::min(25, (*dictList).pos);
14131412
let dictContentSize = ZDICT_dictSize(dictList);
1414-
let mut u: core::ffi::c_uint = 0;
14151413
eprintln!(
14161414
"\n {} segments found, of total size {} ",
14171415
((*dictList).pos).wrapping_sub(1),
14181416
dictContentSize,
14191417
);
14201418
eprintln!("list {} best segments ", nb.wrapping_sub(1));
1421-
u = 1;
1422-
while u < nb {
1419+
for u in 1..nb {
14231420
let pos = (*dictList.offset(u as isize)).pos;
14241421
let length = (*dictList.offset(u as isize)).length;
14251422
let printedLength = Ord::min(40, length);
@@ -1438,7 +1435,6 @@ unsafe fn ZDICT_trainFromBuffer_unsafe_legacy(
14381435
);
14391436
ZDICT_printHex(&samples[..printedLength as usize]);
14401437
eprintln!("|");
1441-
u = u.wrapping_add(1);
14421438
}
14431439
}
14441440

@@ -1496,8 +1492,7 @@ unsafe fn ZDICT_trainFromBuffer_unsafe_legacy(
14961492
// limit dictionary size
14971493
let max = (*dictList).pos; // convention: dictList[0].pos contains the number of useful elements
14981494
let mut currentSize = 0u32;
1499-
let mut n: u32 = 0;
1500-
n = 1;
1495+
let mut n: u32 = 1;
15011496
while n < max {
15021497
currentSize = currentSize.wrapping_add((*dictList.offset(n as isize)).length);
15031498
if currentSize as size_t > targetDictSize {
@@ -1511,11 +1506,9 @@ unsafe fn ZDICT_trainFromBuffer_unsafe_legacy(
15111506
dictContentSize_0 = currentSize;
15121507

15131508
// build dictionary content
1514-
let mut u_0: u32 = 0;
15151509
let mut ptr = (dictBuffer as *mut u8).add(maxDictSize);
1516-
u_0 = 1;
1517-
while u_0 < (*dictList).pos {
1518-
let l = (*dictList.offset(u_0 as isize)).length;
1510+
for u in 1..(*dictList).pos {
1511+
let l = (*dictList.offset(u as isize)).length;
15191512
ptr = ptr.offset(-(l as isize));
15201513
if ptr < dictBuffer as *mut u8 {
15211514
free(dictList as *mut core::ffi::c_void);
@@ -1525,14 +1518,13 @@ unsafe fn ZDICT_trainFromBuffer_unsafe_legacy(
15251518
ptr as *mut core::ffi::c_void,
15261519
samples
15271520
.as_ptr()
1528-
.offset((*dictList.offset(u_0 as isize)).pos as isize)
1521+
.offset((*dictList.offset(u as isize)).pos as isize)
15291522
as *const core::ffi::c_void,
15301523
l as size_t,
15311524
);
1532-
u_0 = u_0.wrapping_add(1);
15331525
}
15341526

1535-
dictSize = ZDICT_addEntropyTablesFromBuffer_advanced(
1527+
let dictSize = ZDICT_addEntropyTablesFromBuffer_advanced(
15361528
dictBuffer,
15371529
dictContentSize_0 as size_t,
15381530
maxDictSize,

0 commit comments

Comments
 (0)