Skip to content

Commit 963fcf7

Browse files
michielp1807folkertdev
authored andcommitted
zdict.rs: use more sensible constant types
1 parent a72267c commit 963fcf7

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

lib/dictBuilder/cover.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ fn train_from_buffer_cover(
883883
}
884884
return Error::srcSize_wrong.to_error_code();
885885
}
886-
if dictBufferCapacity < ZDICT_DICTSIZE_MIN as size_t {
886+
if dictBufferCapacity < ZDICT_DICTSIZE_MIN {
887887
if displayLevel >= 1 {
888888
eprintln!("dictBufferCapacity must be at least {}", 256,);
889889
}
@@ -1129,7 +1129,7 @@ pub(super) fn COVER_selectDict(
11291129
}
11301130
largestDict = dictContentSize;
11311131
largestCompressed = totalCompressedSize;
1132-
dictContentSize = ZDICT_DICTSIZE_MIN as size_t;
1132+
dictContentSize = ZDICT_DICTSIZE_MIN;
11331133
while dictContentSize < largestDict {
11341134
candidateDictBuffer[..largestDict].copy_from_slice(&largestDictbuffer[..largestDict]);
11351135
dictContentSize = unsafe {
@@ -1349,7 +1349,7 @@ unsafe fn optimize_train_from_buffer_cover(
13491349
}
13501350
return Error::srcSize_wrong.to_error_code();
13511351
}
1352-
if dict.len() < ZDICT_DICTSIZE_MIN as size_t {
1352+
if dict.len() < ZDICT_DICTSIZE_MIN {
13531353
if displayLevel >= 1 {
13541354
eprintln!("dictBufferCapacity must be at least {}", 256);
13551355
}

lib/dictBuilder/fastcover.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ fn train_from_buffer_fastcover(
570570
}
571571
return Error::srcSize_wrong.to_error_code();
572572
}
573-
if dictBufferCapacity < ZDICT_DICTSIZE_MIN as size_t {
573+
if dictBufferCapacity < ZDICT_DICTSIZE_MIN {
574574
if displayLevel >= 1 {
575575
eprintln!("dictBufferCapacity must be at least {}", 256);
576576
}
@@ -773,7 +773,7 @@ fn optimize_train_from_buffer_fastcover(
773773
}
774774
return Error::srcSize_wrong.to_error_code();
775775
}
776-
if dict.len() < ZDICT_DICTSIZE_MIN as size_t {
776+
if dict.len() < ZDICT_DICTSIZE_MIN {
777777
if displayLevel >= 1 {
778778
eprintln!("dictBufferCapacity must be at least {}", 256);
779779
}

lib/dictBuilder/zdict.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ impl DictItem {
5858
}
5959
}
6060

61-
const MINRATIO: core::ffi::c_int = 4;
62-
const ZDICT_MAX_SAMPLES_SIZE: core::ffi::c_uint = (2000) << 20;
61+
const MINRATIO: u32 = 4;
62+
const ZDICT_MAX_SAMPLES_SIZE: usize = 2000 << 20;
6363
#[expect(deprecated)]
64-
const ZDICT_MIN_SAMPLES_SIZE: core::ffi::c_int = ZDICT_CONTENTSIZE_MIN * MINRATIO;
64+
const ZDICT_MIN_SAMPLES_SIZE: usize = ZDICT_CONTENTSIZE_MIN as usize * MINRATIO as usize;
6565

66-
const NOISELENGTH: core::ffi::c_int = 32;
66+
const NOISELENGTH: usize = 32;
6767
static g_selectivity_default: u32 = 9;
6868

6969
/// Prints the bytes as characters, with non-printable characters replaced by '.', used for debug output
@@ -597,17 +597,17 @@ unsafe fn ZDICT_trainBuffer_legacy(
597597
if suffix0.is_null() || reverseSuffix.is_null() || doneMarks.is_null() || filePos.is_null() {
598598
result = Error::memory_allocation.to_error_code();
599599
} else {
600-
if minRatio < MINRATIO as core::ffi::c_uint {
601-
minRatio = MINRATIO as core::ffi::c_uint;
600+
if minRatio < MINRATIO {
601+
minRatio = MINRATIO;
602602
}
603603
core::ptr::write_bytes(doneMarks, 0, bufferSize.wrapping_add(16));
604-
if bufferSize > ZDICT_MAX_SAMPLES_SIZE as size_t && notificationLevel >= 3 {
604+
if bufferSize > ZDICT_MAX_SAMPLES_SIZE && notificationLevel >= 3 {
605605
eprintln!(
606606
"sample set too large : reduced to {} MB ...",
607607
(2000) << 20 >> 20,
608608
);
609609
}
610-
while bufferSize > ZDICT_MAX_SAMPLES_SIZE as size_t {
610+
while bufferSize > ZDICT_MAX_SAMPLES_SIZE {
611611
nbFiles = nbFiles.wrapping_sub(1);
612612
bufferSize = bufferSize.wrapping_sub(*fileSizes.offset(nbFiles as isize));
613613
}
@@ -1170,7 +1170,7 @@ unsafe fn finalize_dictionary(
11701170
if dictBufferCapacity < dictContentSize {
11711171
return Err(Error::dstSize_tooSmall);
11721172
}
1173-
if dictBufferCapacity < ZDICT_DICTSIZE_MIN as size_t {
1173+
if dictBufferCapacity < ZDICT_DICTSIZE_MIN {
11741174
return Err(Error::dstSize_tooSmall);
11751175
}
11761176
header[..4].copy_from_slice(&ZSTD_MAGIC_DICTIONARY.to_le_bytes());
@@ -1307,7 +1307,7 @@ unsafe fn ZDICT_trainFromBuffer_unsafe_legacy(
13071307
params.selectivityLevel
13081308
};
13091309
let minRep = if selectivity > 30 {
1310-
MINRATIO as core::ffi::c_uint
1310+
MINRATIO
13111311
} else {
13121312
nbSamples >> selectivity
13131313
};
@@ -1318,11 +1318,11 @@ unsafe fn ZDICT_trainFromBuffer_unsafe_legacy(
13181318
if dictList.is_null() {
13191319
return Error::memory_allocation.to_error_code();
13201320
}
1321-
if maxDictSize < ZDICT_DICTSIZE_MIN as size_t {
1321+
if maxDictSize < ZDICT_DICTSIZE_MIN {
13221322
free(dictList as *mut core::ffi::c_void);
13231323
return Error::dstSize_tooSmall.to_error_code();
13241324
}
1325-
if samplesBuffSize < ZDICT_MIN_SAMPLES_SIZE as size_t {
1325+
if samplesBuffSize < ZDICT_MIN_SAMPLES_SIZE {
13261326
free(dictList as *mut core::ffi::c_void);
13271327
return Error::dictionaryCreation_failed.to_error_code();
13281328
}
@@ -1372,7 +1372,7 @@ unsafe fn ZDICT_trainFromBuffer_unsafe_legacy(
13721372
}
13731373
let mut dictContentSize_0 = ZDICT_dictSize(dictList);
13741374
#[expect(deprecated)]
1375-
if dictContentSize_0 < ZDICT_CONTENTSIZE_MIN as core::ffi::c_uint {
1375+
if dictContentSize_0 < ZDICT_CONTENTSIZE_MIN {
13761376
free(dictList as *mut core::ffi::c_void);
13771377
return Error::dictionaryCreation_failed.to_error_code();
13781378
}
@@ -1387,7 +1387,7 @@ unsafe fn ZDICT_trainFromBuffer_unsafe_legacy(
13871387
samplesBuffSize >> 20,
13881388
);
13891389
}
1390-
if minRep > MINRATIO as core::ffi::c_uint {
1390+
if minRep > MINRATIO {
13911391
eprintln!(
13921392
"! consider increasing selectivity to produce larger dictionary (-s{}) ",
13931393
selectivity.wrapping_add(1),
@@ -1398,12 +1398,12 @@ unsafe fn ZDICT_trainFromBuffer_unsafe_legacy(
13981398
}
13991399
}
14001400
if dictContentSize_0 as size_t > targetDictSize * 3
1401-
&& nbSamples > (2 * MINRATIO) as core::ffi::c_uint
1401+
&& nbSamples > 2 * MINRATIO
14021402
&& selectivity > 1
14031403
&& notificationLevel >= 2
14041404
{
14051405
let mut proposedSelectivity = selectivity.wrapping_sub(1);
1406-
while nbSamples >> proposedSelectivity <= MINRATIO as core::ffi::c_uint {
1406+
while nbSamples >> proposedSelectivity <= MINRATIO {
14071407
proposedSelectivity = proposedSelectivity.wrapping_sub(1);
14081408
}
14091409
eprintln!(
@@ -1514,10 +1514,10 @@ pub unsafe extern "C" fn ZDICT_trainFromBuffer_legacy(
15141514
};
15151515

15161516
let sBuffSize: size_t = samplesSizes.iter().sum();
1517-
if sBuffSize < ZDICT_MIN_SAMPLES_SIZE as size_t {
1517+
if sBuffSize < ZDICT_MIN_SAMPLES_SIZE {
15181518
return 0;
15191519
}
1520-
let mut new_buf = vec![0u8; sBuffSize.wrapping_add(NOISELENGTH as size_t)];
1520+
let mut new_buf = vec![0u8; sBuffSize.wrapping_add(NOISELENGTH)];
15211521
core::ptr::copy_nonoverlapping(samplesBuffer.cast::<u8>(), new_buf.as_mut_ptr(), sBuffSize);
15221522
fill_noise(&mut new_buf[sBuffSize..]);
15231523
ZDICT_trainFromBuffer_unsafe_legacy(

lib/zdict.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ pub use crate::lib::dictBuilder::zdict::{
3333
pub mod experimental {
3434
use super::*;
3535

36-
pub const ZDICT_DICTSIZE_MIN: core::ffi::c_int = 256;
36+
pub const ZDICT_DICTSIZE_MIN: usize = 256;
3737

3838
#[deprecated = "will be removed in v1.6.0"]
39-
pub const ZDICT_CONTENTSIZE_MIN: core::ffi::c_int = 128;
39+
pub const ZDICT_CONTENTSIZE_MIN: u32 = 128;
4040

4141
/// `k` and `d` are the only required parameters. For others, value 0 means default.
4242
#[derive(Debug, Copy, Clone, Default)]

0 commit comments

Comments
 (0)