Skip to content

Commit 5f910ab

Browse files
committed
Remove many redundant casts
1 parent 25ccb66 commit 5f910ab

35 files changed

+430
-693
lines changed

lib/common/entropy_common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn FSE_readNCount_body(
3535
let mut threshold: core::ffi::c_int = 0;
3636
let mut bitStream: u32 = 0;
3737
let mut bitCount: core::ffi::c_int = 0;
38-
let mut charnum = 0 as core::ffi::c_int as core::ffi::c_uint;
38+
let mut charnum = 0 as core::ffi::c_uint;
3939
let maxSV1 = (*maxSVPtr).wrapping_add(1);
4040
let mut previous_was_0 = false;
4141
if hbSize < 8 {

lib/common/error_private.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub const fn ERR_getErrorCode(mut code: size_t) -> ZSTD_ErrorCode {
1515
return 0;
1616
}
1717

18-
(0 as size_t).wrapping_sub(code) as _
18+
code.wrapping_neg() as _
1919
}
2020

2121
#[export_name = crate::prefix!(ERR_getErrorString)]

lib/common/fse_decompress.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ fn FSE_buildDTable_internal(
235235
.wrapping_add(tableSize >> 3)
236236
.wrapping_add(3) as size_t;
237237
let add = 0x101010101010101 as core::ffi::c_ulonglong as u64;
238-
let mut pos = 0 as core::ffi::c_int as size_t;
239-
let mut sv = 0 as core::ffi::c_int as u64;
238+
let mut pos = 0 as size_t;
239+
let mut sv = 0u64;
240240

241241
for s_0 in 0..maxSV1 {
242242
let mut i: core::ffi::c_int = 0;
@@ -251,7 +251,7 @@ fn FSE_buildDTable_internal(
251251
sv = sv.wrapping_add(add);
252252
}
253253

254-
let mut position = 0 as core::ffi::c_int as size_t;
254+
let mut position = 0 as size_t;
255255
let mut s_1: size_t = 0;
256256
let unroll = 2;
257257
s_1 = 0;
@@ -272,7 +272,7 @@ fn FSE_buildDTable_internal(
272272
.wrapping_add(tableSize >> 3)
273273
.wrapping_add(3);
274274

275-
let mut position_0 = 0 as core::ffi::c_int as u32;
275+
let mut position_0 = 0u32;
276276
for s_2 in 0..maxSV1 {
277277
for _ in 0..normalizedCounter[s_2 as usize] {
278278
elements[position_0 as usize].symbol = s_2 as u8;

lib/compress/fse_compress.rs

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35,41 +35,12 @@ unsafe extern "C" fn ZSTD_countLeadingZeros32(mut val: u32) -> core::ffi::c_uint
3535
}
3636
#[inline]
3737
unsafe extern "C" fn ZSTD_highbit32(mut val: u32) -> core::ffi::c_uint {
38-
(31 as core::ffi::c_int as core::ffi::c_uint).wrapping_sub(ZSTD_countLeadingZeros32(val))
38+
(31 as core::ffi::c_uint).wrapping_sub(ZSTD_countLeadingZeros32(val))
3939
}
4040
static BIT_mask: [core::ffi::c_uint; 32] = [
41-
0 as core::ffi::c_int as core::ffi::c_uint,
42-
1 as core::ffi::c_int as core::ffi::c_uint,
43-
3 as core::ffi::c_int as core::ffi::c_uint,
44-
7 as core::ffi::c_int as core::ffi::c_uint,
45-
0xf as core::ffi::c_int as core::ffi::c_uint,
46-
0x1f as core::ffi::c_int as core::ffi::c_uint,
47-
0x3f as core::ffi::c_int as core::ffi::c_uint,
48-
0x7f as core::ffi::c_int as core::ffi::c_uint,
49-
0xff as core::ffi::c_int as core::ffi::c_uint,
50-
0x1ff as core::ffi::c_int as core::ffi::c_uint,
51-
0x3ff as core::ffi::c_int as core::ffi::c_uint,
52-
0x7ff as core::ffi::c_int as core::ffi::c_uint,
53-
0xfff as core::ffi::c_int as core::ffi::c_uint,
54-
0x1fff as core::ffi::c_int as core::ffi::c_uint,
55-
0x3fff as core::ffi::c_int as core::ffi::c_uint,
56-
0x7fff as core::ffi::c_int as core::ffi::c_uint,
57-
0xffff as core::ffi::c_int as core::ffi::c_uint,
58-
0x1ffff as core::ffi::c_int as core::ffi::c_uint,
59-
0x3ffff as core::ffi::c_int as core::ffi::c_uint,
60-
0x7ffff as core::ffi::c_int as core::ffi::c_uint,
61-
0xfffff as core::ffi::c_int as core::ffi::c_uint,
62-
0x1fffff as core::ffi::c_int as core::ffi::c_uint,
63-
0x3fffff as core::ffi::c_int as core::ffi::c_uint,
64-
0x7fffff as core::ffi::c_int as core::ffi::c_uint,
65-
0xffffff as core::ffi::c_int as core::ffi::c_uint,
66-
0x1ffffff as core::ffi::c_int as core::ffi::c_uint,
67-
0x3ffffff as core::ffi::c_int as core::ffi::c_uint,
68-
0x7ffffff as core::ffi::c_int as core::ffi::c_uint,
69-
0xfffffff as core::ffi::c_int as core::ffi::c_uint,
70-
0x1fffffff as core::ffi::c_int as core::ffi::c_uint,
71-
0x3fffffff as core::ffi::c_int as core::ffi::c_uint,
72-
0x7fffffff as core::ffi::c_int as core::ffi::c_uint,
41+
0, 1, 3, 7, 0xf, 0x1f, 0x3f, 0x7f, 0xff, 0x1ff, 0x3ff, 0x7ff, 0xfff, 0x1fff, 0x3fff, 0x7fff,
42+
0xffff, 0x1ffff, 0x3ffff, 0x7ffff, 0xfffff, 0x1fffff, 0x3fffff, 0x7fffff, 0xffffff, 0x1ffffff,
43+
0x3ffffff, 0x7ffffff, 0xfffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
7344
];
7445
#[inline]
7546
unsafe extern "C" fn BIT_initCStream(
@@ -273,8 +244,8 @@ pub unsafe extern "C" fn FSE_buildCTable_wksp(
273244
if highThreshold == tableSize.wrapping_sub(1) {
274245
let spread = tableSymbol.offset(tableSize as isize);
275246
let add = 0x101010101010101 as core::ffi::c_ulonglong as u64;
276-
let mut pos = 0 as core::ffi::c_int as size_t;
277-
let mut sv = 0 as core::ffi::c_int as u64;
247+
let mut pos = 0 as size_t;
248+
let mut sv = 0u64;
278249
let mut s: u32 = 0;
279250
s = 0;
280251
while s < maxSV1 {
@@ -293,7 +264,7 @@ pub unsafe extern "C" fn FSE_buildCTable_wksp(
293264
s = s.wrapping_add(1);
294265
sv = sv.wrapping_add(add);
295266
}
296-
let mut position = 0 as core::ffi::c_int as size_t;
267+
let mut position = 0 as size_t;
297268
let mut s_0: size_t = 0;
298269
let unroll = 2;
299270
s_0 = 0;
@@ -310,7 +281,7 @@ pub unsafe extern "C" fn FSE_buildCTable_wksp(
310281
s_0 = s_0.wrapping_add(unroll);
311282
}
312283
} else {
313-
let mut position_0 = 0 as core::ffi::c_int as u32;
284+
let mut position_0 = 0u32;
314285
let mut symbol: u32 = 0;
315286
symbol = 0;
316287
while symbol < maxSV1 {
@@ -338,7 +309,7 @@ pub unsafe extern "C" fn FSE_buildCTable_wksp(
338309
*tableU16.offset(fresh2 as isize) = tableSize.wrapping_add(u_1) as u16;
339310
u_1 = u_1.wrapping_add(1);
340311
}
341-
let mut total = 0 as core::ffi::c_int as core::ffi::c_uint;
312+
let mut total = 0 as core::ffi::c_uint;
342313
let mut s_2: core::ffi::c_uint = 0;
343314
s_2 = 0;
344315
while s_2 <= maxSymbolValue {
@@ -593,7 +564,7 @@ unsafe extern "C" fn FSE_normalizeM2(
593564
) -> size_t {
594565
let NOT_YET_ASSIGNED = -(2) as core::ffi::c_short;
595566
let mut s: u32 = 0;
596-
let mut distributed = 0 as core::ffi::c_int as u32;
567+
let mut distributed = 0u32;
597568
let mut ToDistribute: u32 = 0;
598569
let lowThreshold = (total >> tableLog) as u32;
599570
let mut lowOne = ((total * 3) >> tableLog.wrapping_add(1)) as u32;
@@ -614,7 +585,7 @@ unsafe extern "C" fn FSE_normalizeM2(
614585
}
615586
s = s.wrapping_add(1);
616587
}
617-
ToDistribute = (((1) << tableLog) as u32).wrapping_sub(distributed);
588+
ToDistribute = ((1 << tableLog) as u32).wrapping_sub(distributed);
618589
if ToDistribute == 0 {
619590
return 0;
620591
}
@@ -631,7 +602,7 @@ unsafe extern "C" fn FSE_normalizeM2(
631602
}
632603
s = s.wrapping_add(1);
633604
}
634-
ToDistribute = (((1) << tableLog) as u32).wrapping_sub(distributed);
605+
ToDistribute = ((1 << tableLog) as u32).wrapping_sub(distributed);
635606
}
636607
if distributed == maxSymbolValue.wrapping_add(1) {
637608
let mut maxV = 0;
@@ -662,10 +633,9 @@ unsafe extern "C" fn FSE_normalizeM2(
662633
}
663634
return 0;
664635
}
665-
let vStepLog = (62 as core::ffi::c_int as u32).wrapping_sub(tableLog) as u64;
666-
let mid = ((1 as core::ffi::c_ulonglong) << vStepLog.wrapping_sub(1 as core::ffi::c_int as u64))
667-
.wrapping_sub(1 as core::ffi::c_int as core::ffi::c_ulonglong) as u64;
668-
let rStep = (((1) << vStepLog) * ToDistribute as u64).wrapping_add(mid) / total as u32 as u64;
636+
let vStepLog = 62u32.wrapping_sub(tableLog) as u64;
637+
let mid = ((1 as core::ffi::c_ulonglong) << vStepLog.wrapping_sub(1)).wrapping_sub(1) as u64;
638+
let rStep = ((1 << vStepLog) * ToDistribute as u64).wrapping_add(mid) / total as u32 as u64;
669639
let mut tmpTotal = mid;
670640
s = 0;
671641
while s <= maxSymbolValue {
@@ -707,9 +677,9 @@ pub unsafe extern "C" fn FSE_normalizeCount(
707677
}
708678
static rtbTable: [u32; 8] = [0, 473195, 504333, 520860, 550000, 700000, 750000, 830000];
709679
let lowProbCount = (if useLowProbCount != 0 { -(1) } else { 1 }) as core::ffi::c_short;
710-
let scale = (62 as core::ffi::c_int as core::ffi::c_uint).wrapping_sub(tableLog) as u64;
711-
let step = ((1) << 62) / total as u32 as u64;
712-
let vStep = ((1) << scale.wrapping_sub(20)) as u64;
680+
let scale = (62 as core::ffi::c_uint).wrapping_sub(tableLog) as u64;
681+
let step = (1 << 62) / total as u32 as u64;
682+
let vStep = (1 << scale.wrapping_sub(20)) as u64;
713683
let mut stillToDistribute = (1) << tableLog;
714684
let mut s: core::ffi::c_uint = 0;
715685
let mut largest = 0;

lib/compress/hist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ unsafe extern "C" fn HIST_count_parallel_wksp(
170170
}
171171
s = s.wrapping_add(1);
172172
}
173-
let mut maxSymbolValue = 255 as core::ffi::c_int as core::ffi::c_uint;
173+
let mut maxSymbolValue = 255 as core::ffi::c_uint;
174174
while *Counting1.offset(maxSymbolValue as isize) == 0 {
175175
maxSymbolValue = maxSymbolValue.wrapping_sub(1);
176176
}

lib/compress/huf_compress.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const fn ZSTD_countLeadingZeros32(mut val: u32) -> core::ffi::c_uint {
9999
}
100100
#[inline]
101101
const fn ZSTD_highbit32(mut val: u32) -> core::ffi::c_uint {
102-
(31 as core::ffi::c_int as core::ffi::c_uint).wrapping_sub(ZSTD_countLeadingZeros32(val))
102+
(31 as core::ffi::c_uint).wrapping_sub(ZSTD_countLeadingZeros32(val))
103103
}
104104
pub const HUF_BLOCKSIZE_MAX: core::ffi::c_int = 128 * 1024;
105105
pub const HUF_TABLELOG_MAX: core::ffi::c_int = 12;
@@ -343,9 +343,7 @@ pub unsafe extern "C" fn HUF_writeCTable_wksp(
343343
{
344344
return -(ZSTD_error_dstSize_tooSmall as core::ffi::c_int) as size_t;
345345
}
346-
*op.offset(0 as core::ffi::c_int as isize) = (128 as core::ffi::c_int as core::ffi::c_uint)
347-
.wrapping_add(maxSymbolValue.wrapping_sub(1 as core::ffi::c_int as core::ffi::c_uint))
348-
as u8;
346+
*op.offset(0) = (128 as core::ffi::c_uint).wrapping_add(maxSymbolValue.wrapping_sub(1)) as u8;
349347
*((*wksp).huffWeight)
350348
.as_mut_ptr()
351349
.offset(maxSymbolValue as isize) = 0;
@@ -400,7 +398,7 @@ pub unsafe fn HUF_readCTable(
400398
*maxSymbolValuePtr = nbSymbols.wrapping_sub(1);
401399
HUF_writeCTableHeader(CTable, tableLog, *maxSymbolValuePtr);
402400
let mut n: u32 = 0;
403-
let mut nextRankStart = 0 as core::ffi::c_int as u32;
401+
let mut nextRankStart = 0u32;
404402
n = 1;
405403
while n <= tableLog {
406404
let mut curr = nextRankStart;
@@ -896,7 +894,7 @@ pub unsafe extern "C" fn HUF_estimateCompressedSize(
896894
mut maxSymbolValue: core::ffi::c_uint,
897895
) -> size_t {
898896
let mut ct = CTable.offset(1);
899-
let mut nbBits = 0 as core::ffi::c_int as size_t;
897+
let mut nbBits = 0 as size_t;
900898
let mut s: core::ffi::c_int = 0;
901899
s = 0;
902900
while s <= maxSymbolValue as core::ffi::c_int {
@@ -1368,12 +1366,12 @@ pub unsafe extern "C" fn HUF_cardinality(
13681366
mut count: *const core::ffi::c_uint,
13691367
mut maxSymbolValue: core::ffi::c_uint,
13701368
) -> core::ffi::c_uint {
1371-
let mut cardinality = 0 as core::ffi::c_int as core::ffi::c_uint;
1369+
let mut cardinality = 0 as core::ffi::c_uint;
13721370
let mut i: core::ffi::c_uint = 0;
13731371
i = 0;
13741372
while i < maxSymbolValue.wrapping_add(1) {
13751373
if *count.offset(i as isize) != 0 {
1376-
cardinality = cardinality.wrapping_add(1 as core::ffi::c_int as core::ffi::c_uint);
1374+
cardinality = cardinality.wrapping_add(1);
13771375
}
13781376
i = i.wrapping_add(1);
13791377
}
@@ -1514,7 +1512,7 @@ unsafe extern "C" fn HUF_compress_internal(
15141512
&& srcSize
15151513
>= (SUSPECT_INCOMPRESSIBLE_SAMPLE_SIZE * SUSPECT_INCOMPRESSIBLE_SAMPLE_RATIO) as size_t
15161514
{
1517-
let mut largestTotal = 0 as core::ffi::c_int as size_t;
1515+
let mut largestTotal = 0 as size_t;
15181516
let mut maxSymbolValueBegin = maxSymbolValue;
15191517
let largestBegin = HIST_count_simple(
15201518
((*table).count).as_mut_ptr(),

0 commit comments

Comments
 (0)