-
-
Notifications
You must be signed in to change notification settings - Fork 2
Use T::from instead of cast where expected to be lossless. #254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
46eea01 to
fd0e007
Compare
fd0e007 to
02ee2a6
Compare
folkertdev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to only apply this change only to the parts of the code that we've already cleaned up manually. Let's start with lib/dictBuilder. Can you
- remove changes to the other subdirectories from the initial commit
- fix the other comments I've left in a separate commit (that is easier to review)
| let mut candidateDictBuffer: Box<[u8]> = Box::from(vec![0u8; dictBufferCapacity]); | ||
| let regressionTolerance = | ||
| params.shrinkDictMaxRegression as core::ffi::c_double / 100.0f64 + 1.00f64; | ||
| core::ffi::c_double::from(params.shrinkDictMaxRegression) / 100.0f64 + 1.00f64; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should import use core::ffi::c_double so we can use it unqualified here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same in the other files for the other core::ffi types.
| assert!(T[(s - 1) as usize] as i32 <= T[s as usize] as i32); | ||
| assert_eq!(i32::from(T[s as usize]), c1); | ||
| assert!( | ||
| (s + 1) < n && i32::from(T[s as usize]) <= i32::from(T[(s + 1) as usize]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the cast is just not needed here (c2rust introduces it to exactly match the C semantics, but we can just compare u8s here.
| #[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZDICT_isError))] | ||
| pub extern "C" fn ZDICT_isError(errorCode: size_t) -> core::ffi::c_uint { | ||
| ERR_isError(errorCode) as _ | ||
| ERR_isError(errorCode).into() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer c_uint::from here.
| // look backward | ||
| let mut length_2 = MINMATCHLENGTH; | ||
| while (length_2 >= MINMATCHLENGTH) as core::ffi::c_int & (start > 0) as core::ffi::c_int != 0 { | ||
| while core::ffi::c_int::from(length_2 >= MINMATCHLENGTH) & core::ffi::c_int::from(start > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be simplified into length_2 >= MINMATCHLENGTH && start > 0
Fix lints from
clippy::cast_lossless