Skip to content

Commit 0267dec

Browse files
committed
Constantly casted constants cleanup
1 parent aded68b commit 0267dec

File tree

9 files changed

+88
-94
lines changed

9 files changed

+88
-94
lines changed

lib/common/zstd_internal.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ pub(crate) const bt_compressed: blockType_e = 2;
2424

2525
pub(crate) const MINMATCH: core::ffi::c_int = 3;
2626

27-
pub(crate) const Litbits: core::ffi::c_int = 8;
28-
pub(crate) const LitHufLog: core::ffi::c_int = 11;
29-
pub(crate) const MaxLit: core::ffi::c_int = ((1) << Litbits) - 1;
30-
pub(crate) const MaxML: core::ffi::c_int = 52;
31-
pub(crate) const MaxLL: core::ffi::c_int = 35;
32-
pub(crate) const DefaultMaxOff: core::ffi::c_int = 28;
33-
pub(crate) const MaxOff: core::ffi::c_int = 31;
27+
pub(crate) const Litbits: u32 = 8;
28+
pub(crate) const LitHufLog: u32 = 11;
29+
pub(crate) const MaxLit: u32 = (1 << Litbits) - 1;
30+
pub(crate) const MaxML: u32 = 52;
31+
pub(crate) const MaxLL: u32 = 35;
32+
pub(crate) const DefaultMaxOff: u32 = 28;
33+
pub(crate) const MaxOff: u32 = 31;
3434
pub(crate) const MaxSeq: usize = const_max(MaxLL as usize, MaxML as usize); /* Assumption : MaxOff < MaxLL,MaxML */
35-
pub(crate) const MLFSELog: core::ffi::c_int = 9;
36-
pub(crate) const LLFSELog: core::ffi::c_int = 9;
37-
pub(crate) const OffFSELog: core::ffi::c_int = 8;
35+
pub(crate) const MLFSELog: u32 = 9;
36+
pub(crate) const LLFSELog: u32 = 9;
37+
pub(crate) const OffFSELog: u32 = 8;
3838
pub(crate) const MaxFSELog: usize = const_max(
3939
const_max(MLFSELog as usize, LLFSELog as usize),
4040
OffFSELog as usize,

lib/compress/zstd_compress.rs

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4655,7 +4655,7 @@ unsafe fn ZSTD_buildSequencesStatistics(
46554655
};
46564656
stats.lastCountSize = 0;
46574657
stats.longOffsets = ZSTD_seqToCodes(seqStorePtr);
4658-
let mut max = MaxLL as core::ffi::c_uint;
4658+
let mut max = MaxLL;
46594659
let mostFrequent = HIST_countFast_wksp(
46604660
countWorkspace,
46614661
&mut max,
@@ -4671,7 +4671,7 @@ unsafe fn ZSTD_buildSequencesStatistics(
46714671
max,
46724672
mostFrequent,
46734673
nbSeq,
4674-
LLFSELog as core::ffi::c_uint,
4674+
LLFSELog,
46754675
((*prevEntropy).litlengthCTable).as_ptr(),
46764676
LL_defaultNorm.as_ptr(),
46774677
LL_defaultNormLog,
@@ -4682,15 +4682,15 @@ unsafe fn ZSTD_buildSequencesStatistics(
46824682
op as *mut core::ffi::c_void,
46834683
oend.offset_from_unsigned(op),
46844684
CTable_LitLength,
4685-
LLFSELog as u32,
4685+
LLFSELog,
46864686
stats.LLtype as SymbolEncodingType_e,
46874687
countWorkspace,
46884688
max,
46894689
llCodeTable,
46904690
nbSeq,
46914691
LL_defaultNorm.as_ptr(),
46924692
LL_defaultNormLog,
4693-
MaxLL as u32,
4693+
MaxLL,
46944694
((*prevEntropy).litlengthCTable).as_ptr(),
46954695
::core::mem::size_of::<[FSE_CTable; 329]>(),
46964696
entropyWorkspace,
@@ -4704,7 +4704,7 @@ unsafe fn ZSTD_buildSequencesStatistics(
47044704
stats.lastCountSize = countSize;
47054705
}
47064706
op = op.add(countSize);
4707-
let mut max_0 = MaxOff as core::ffi::c_uint;
4707+
let mut max_0 = MaxOff;
47084708
let mostFrequent_0 = HIST_countFast_wksp(
47094709
countWorkspace,
47104710
&mut max_0,
@@ -4713,7 +4713,7 @@ unsafe fn ZSTD_buildSequencesStatistics(
47134713
entropyWorkspace,
47144714
entropyWkspSize,
47154715
);
4716-
let defaultPolicy = (if max_0 <= DefaultMaxOff as core::ffi::c_uint {
4716+
let defaultPolicy = (if max_0 <= DefaultMaxOff {
47174717
ZSTD_defaultAllowed as core::ffi::c_int
47184718
} else {
47194719
ZSTD_defaultDisallowed as core::ffi::c_int
@@ -4725,7 +4725,7 @@ unsafe fn ZSTD_buildSequencesStatistics(
47254725
max_0,
47264726
mostFrequent_0,
47274727
nbSeq,
4728-
OffFSELog as core::ffi::c_uint,
4728+
OffFSELog,
47294729
((*prevEntropy).offcodeCTable).as_ptr(),
47304730
OF_defaultNorm.as_ptr(),
47314731
OF_defaultNormLog,
@@ -4736,15 +4736,15 @@ unsafe fn ZSTD_buildSequencesStatistics(
47364736
op as *mut core::ffi::c_void,
47374737
oend.offset_from_unsigned(op),
47384738
CTable_OffsetBits,
4739-
OffFSELog as u32,
4739+
OffFSELog,
47404740
stats.Offtype as SymbolEncodingType_e,
47414741
countWorkspace,
47424742
max_0,
47434743
ofCodeTable,
47444744
nbSeq,
47454745
OF_defaultNorm.as_ptr(),
47464746
OF_defaultNormLog,
4747-
DefaultMaxOff as u32,
4747+
DefaultMaxOff,
47484748
((*prevEntropy).offcodeCTable).as_ptr(),
47494749
::core::mem::size_of::<[FSE_CTable; 193]>(),
47504750
entropyWorkspace,
@@ -4758,7 +4758,7 @@ unsafe fn ZSTD_buildSequencesStatistics(
47584758
stats.lastCountSize = countSize_0;
47594759
}
47604760
op = op.add(countSize_0);
4761-
let mut max_1 = MaxML as core::ffi::c_uint;
4761+
let mut max_1 = MaxML;
47624762
let mostFrequent_1 = HIST_countFast_wksp(
47634763
countWorkspace,
47644764
&mut max_1,
@@ -4774,7 +4774,7 @@ unsafe fn ZSTD_buildSequencesStatistics(
47744774
max_1,
47754775
mostFrequent_1,
47764776
nbSeq,
4777-
MLFSELog as core::ffi::c_uint,
4777+
MLFSELog,
47784778
((*prevEntropy).matchlengthCTable).as_ptr(),
47794779
ML_defaultNorm.as_ptr(),
47804780
ML_defaultNormLog,
@@ -4785,15 +4785,15 @@ unsafe fn ZSTD_buildSequencesStatistics(
47854785
op as *mut core::ffi::c_void,
47864786
oend.offset_from_unsigned(op),
47874787
CTable_MatchLength,
4788-
MLFSELog as u32,
4788+
MLFSELog,
47894789
stats.MLtype as SymbolEncodingType_e,
47904790
countWorkspace,
47914791
max_1,
47924792
mlCodeTable,
47934793
nbSeq,
47944794
ML_defaultNorm.as_ptr(),
47954795
ML_defaultNormLog,
4796-
MaxML as u32,
4796+
MaxML,
47974797
((*prevEntropy).matchlengthCTable).as_ptr(),
47984798
::core::mem::size_of::<[FSE_CTable; 363]>(),
47994799
entropyWorkspace,
@@ -5659,7 +5659,7 @@ unsafe fn ZSTD_buildBlockEntropyStats_literals(
56595659
let nodeWksp = countWkspStart.add(countWkspSize);
56605660
let nodeWkspSize = wkspEnd.offset_from_unsigned(nodeWksp);
56615661
let mut maxSymbolValue = HUF_SYMBOLVALUE_MAX as core::ffi::c_uint;
5662-
let mut huffLog = LitHufLog as core::ffi::c_uint;
5662+
let mut huffLog = LitHufLog;
56635663
let mut repeat = (*prevHuf).repeatMode;
56645664
libc::memcpy(
56655665
nextHuf as *mut core::ffi::c_void,
@@ -6020,38 +6020,38 @@ unsafe fn ZSTD_estimateBlockSize_sequences(
60206020
(*fseMetadata).ofType,
60216021
ofCodeTable,
60226022
nbSeq,
6023-
MaxOff as core::ffi::c_uint,
6023+
MaxOff,
60246024
((*fseTables).offcodeCTable).as_ptr(),
60256025
core::ptr::null(),
60266026
OF_defaultNorm.as_ptr(),
60276027
OF_defaultNormLog,
6028-
DefaultMaxOff as u32,
6028+
DefaultMaxOff,
60296029
workspace,
60306030
wkspSize,
60316031
));
60326032
cSeqSizeEstimate = cSeqSizeEstimate.wrapping_add(ZSTD_estimateBlockSize_symbolType(
60336033
(*fseMetadata).llType,
60346034
llCodeTable,
60356035
nbSeq,
6036-
MaxLL as core::ffi::c_uint,
6036+
MaxLL,
60376037
((*fseTables).litlengthCTable).as_ptr(),
60386038
LL_bits.as_ptr(),
60396039
LL_defaultNorm.as_ptr(),
60406040
LL_defaultNormLog,
6041-
MaxLL as u32,
6041+
MaxLL,
60426042
workspace,
60436043
wkspSize,
60446044
));
60456045
cSeqSizeEstimate = cSeqSizeEstimate.wrapping_add(ZSTD_estimateBlockSize_symbolType(
60466046
(*fseMetadata).mlType,
60476047
mlCodeTable,
60486048
nbSeq,
6049-
MaxML as core::ffi::c_uint,
6049+
MaxML,
60506050
((*fseTables).matchlengthCTable).as_ptr(),
60516051
ML_bits.as_ptr(),
60526052
ML_defaultNorm.as_ptr(),
60536053
ML_defaultNormLog,
6054-
MaxML as u32,
6054+
MaxML,
60556055
workspace,
60566056
wkspSize,
60576057
));
@@ -7343,7 +7343,7 @@ pub unsafe fn ZSTD_loadCEntropy(
73437343
dictSize: size_t,
73447344
) -> size_t {
73457345
let mut offcodeNCount: [core::ffi::c_short; 32] = [0; 32];
7346-
let mut offcodeMaxValue = MaxOff as core::ffi::c_uint;
7346+
let mut offcodeMaxValue = MaxOff;
73477347
let mut dictPtr = dict as *const u8;
73487348
let dictEnd = dictPtr.add(dictSize);
73497349
dictPtr = dictPtr.add(8);
@@ -7390,7 +7390,7 @@ pub unsafe fn ZSTD_loadCEntropy(
73907390
}
73917391
dictPtr = dictPtr.add(offcodeHeaderSize);
73927392
let mut matchlengthNCount: [core::ffi::c_short; 53] = [0; 53];
7393-
let mut matchlengthMaxValue = MaxML as core::ffi::c_uint;
7393+
let mut matchlengthMaxValue = MaxML;
73947394
let mut matchlengthLog: core::ffi::c_uint = 0;
73957395
let matchlengthHeaderSize = FSE_readNCount(
73967396
&mut matchlengthNCount,
@@ -7415,14 +7415,11 @@ pub unsafe fn ZSTD_loadCEntropy(
74157415
)) {
74167416
return Error::dictionary_corrupted.to_error_code();
74177417
}
7418-
(*bs).entropy.fse.matchlength_repeatMode = ZSTD_dictNCountRepeat(
7419-
matchlengthNCount.as_mut_ptr(),
7420-
matchlengthMaxValue,
7421-
MaxML as core::ffi::c_uint,
7422-
);
7418+
(*bs).entropy.fse.matchlength_repeatMode =
7419+
ZSTD_dictNCountRepeat(matchlengthNCount.as_mut_ptr(), matchlengthMaxValue, MaxML);
74237420
dictPtr = dictPtr.add(matchlengthHeaderSize);
74247421
let mut litlengthNCount: [core::ffi::c_short; 36] = [0; 36];
7425-
let mut litlengthMaxValue = MaxLL as core::ffi::c_uint;
7422+
let mut litlengthMaxValue = MaxLL;
74267423
let mut litlengthLog: core::ffi::c_uint = 0;
74277424
let litlengthHeaderSize = FSE_readNCount(
74287425
&mut litlengthNCount,
@@ -7447,11 +7444,8 @@ pub unsafe fn ZSTD_loadCEntropy(
74477444
)) {
74487445
return Error::dictionary_corrupted.to_error_code();
74497446
}
7450-
(*bs).entropy.fse.litlength_repeatMode = ZSTD_dictNCountRepeat(
7451-
litlengthNCount.as_mut_ptr(),
7452-
litlengthMaxValue,
7453-
MaxLL as core::ffi::c_uint,
7454-
);
7447+
(*bs).entropy.fse.litlength_repeatMode =
7448+
ZSTD_dictNCountRepeat(litlengthNCount.as_mut_ptr(), litlengthMaxValue, MaxLL);
74557449
dictPtr = dictPtr.add(litlengthHeaderSize);
74567450
if dictPtr.add(12) > dictEnd {
74577451
return Error::dictionary_corrupted.to_error_code();
@@ -7461,7 +7455,7 @@ pub unsafe fn ZSTD_loadCEntropy(
74617455
*((*bs).rep).as_mut_ptr().add(2) = MEM_readLE32(dictPtr.add(8) as *const core::ffi::c_void);
74627456
dictPtr = dictPtr.add(12);
74637457
let dictContentSize = dictEnd.offset_from_unsigned(dictPtr);
7464-
let mut offcodeMax = MaxOff as u32;
7458+
let mut offcodeMax = MaxOff;
74657459
if dictContentSize
74667460
<= (-(1 as core::ffi::c_int) as u32)
74677461
.wrapping_sub((128 as core::ffi::c_int * ((1 as core::ffi::c_int) << 10)) as u32)

lib/compress/zstd_compress_literals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ pub unsafe fn ZSTD_compressLiterals(
251251
src,
252252
srcSize,
253253
HUF_SYMBOLVALUE_MAX as core::ffi::c_uint,
254-
LitHufLog as core::ffi::c_uint,
254+
LitHufLog,
255255
entropyWorkspace,
256256
entropyWorkspaceSize,
257257
((*nextHuf).CTable).as_mut_ptr(),

lib/compress/zstd_compress_sequences.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ unsafe fn ZSTD_encodeSequences_body(
473473
);
474474
if MEM_32bits()
475475
|| ofBits_0.wrapping_add(mlBits).wrapping_add(llBits)
476-
>= (64 - 7 - (LLFSELog + MLFSELog + OffFSELog)) as u32
476+
>= 64 - 7 - (LLFSELog + MLFSELog + OffFSELog)
477477
{
478478
BIT_flushBits(&mut blockStream);
479479
}

lib/compress/zstd_compress_superblock.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -736,39 +736,39 @@ unsafe fn ZSTD_estimateSubBlockSize_sequences(
736736
cSeqSizeEstimate = cSeqSizeEstimate.wrapping_add(ZSTD_estimateSubBlockSize_symbolType(
737737
(*fseMetadata).ofType,
738738
ofCodeTable,
739-
MaxOff as core::ffi::c_uint,
739+
MaxOff,
740740
nbSeq,
741741
((*fseTables).offcodeCTable).as_ptr(),
742742
core::ptr::null(),
743743
OF_defaultNorm.as_ptr(),
744744
OF_defaultNormLog,
745-
DefaultMaxOff as u32,
745+
DefaultMaxOff,
746746
workspace,
747747
wkspSize,
748748
));
749749
cSeqSizeEstimate = cSeqSizeEstimate.wrapping_add(ZSTD_estimateSubBlockSize_symbolType(
750750
(*fseMetadata).llType,
751751
llCodeTable,
752-
MaxLL as core::ffi::c_uint,
752+
MaxLL,
753753
nbSeq,
754754
((*fseTables).litlengthCTable).as_ptr(),
755755
LL_bits.as_ptr(),
756756
LL_defaultNorm.as_ptr(),
757757
LL_defaultNormLog,
758-
MaxLL as u32,
758+
MaxLL,
759759
workspace,
760760
wkspSize,
761761
));
762762
cSeqSizeEstimate = cSeqSizeEstimate.wrapping_add(ZSTD_estimateSubBlockSize_symbolType(
763763
(*fseMetadata).mlType,
764764
mlCodeTable,
765-
MaxML as core::ffi::c_uint,
765+
MaxML,
766766
nbSeq,
767767
((*fseTables).matchlengthCTable).as_ptr(),
768768
ML_bits.as_ptr(),
769769
ML_defaultNorm.as_ptr(),
770770
ML_defaultNormLog,
771-
MaxML as u32,
771+
MaxML,
772772
workspace,
773773
wkspSize,
774774
));

0 commit comments

Comments
 (0)