Skip to content

Commit 13c3610

Browse files
committed
fix: clippy
1 parent f990ee8 commit 13c3610

6 files changed

Lines changed: 21 additions & 34 deletions

File tree

float-pigment-consistent-bincode/src/config/int.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl VarintEncoding {
206206

207207
#[inline(always)]
208208
fn zigzag_decode(n: u64) -> i64 {
209-
if n % 2 == 0 {
209+
if n.is_multiple_of(2) {
210210
// positive number
211211
(n / 2) as i64
212212
} else {
@@ -269,7 +269,7 @@ impl VarintEncoding {
269269
}
270270
#[inline(always)]
271271
fn zigzag128_decode(n: u128) -> i128 {
272-
if n % 2 == 0 {
272+
if n.is_multiple_of(2) {
273273
(n / 2) as i128
274274
} else {
275275
!(n / 2) as i128

float-pigment-css/src/ffi.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ pub unsafe extern "C" fn style_sheet_resource_add_bincode(
352352
check_null!(path, FfiErrorCode::PathNullPointer, null());
353353
check_null!(buffer_ptr, FfiErrorCode::BufferNullPointer, null());
354354
let res = raw_ptr_as_mut_ref!(this, group::StyleSheetResource);
355-
let bincode: *mut [u8] = core::slice::from_raw_parts_mut(buffer_ptr, buffer_len);
355+
let bincode: *mut [u8] = core::ptr::slice_from_raw_parts_mut(buffer_ptr, buffer_len);
356356
let path = CStr::from_ptr(path).to_string_lossy();
357357
let w = res.add_bincode_zero_copy(&path, bincode, move || {
358358
if let Some(drop_fn) = drop_fn {
@@ -595,7 +595,7 @@ pub unsafe extern "C" fn style_sheet_import_index_add_bincode(
595595
check_null!(buffer_ptr, FfiErrorCode::BufferNullPointer, null_mut());
596596
let path = CStr::from_ptr(path).to_string_lossy();
597597
let sheet = de_static_ref_zero_copy_env(
598-
core::slice::from_raw_parts_mut(buffer_ptr, buffer_len),
598+
core::ptr::slice_from_raw_parts_mut(buffer_ptr, buffer_len),
599599
|s| {
600600
let s: Result<StyleSheet, _> = float_pigment_consistent_bincode::DefaultOptions::new()
601601
.allow_trailing_bytes()
@@ -790,7 +790,7 @@ pub unsafe extern "C" fn style_sheet_import_index_deserialize_bincode(
790790
drop_args: RawMutPtr,
791791
) -> FfiResult<RawMutPtr> {
792792
check_null!(buffer_ptr, FfiErrorCode::BufferNullPointer, null_mut());
793-
let bincode: *mut [u8] = core::slice::from_raw_parts_mut(buffer_ptr, buffer_len);
793+
let bincode: *mut [u8] = core::ptr::slice_from_raw_parts_mut(buffer_ptr, buffer_len);
794794
FfiResult::ok(
795795
StyleSheetImportIndex {
796796
inner: StyleSheetImportIndexImpl::deserialize_bincode_zero_copy(bincode, move || {
@@ -831,7 +831,7 @@ pub unsafe extern "C" fn style_sheet_import_index_merge_bincode(
831831
check_null!(this, FfiErrorCode::ThisNullPointer, null());
832832
check_null!(buffer_ptr, FfiErrorCode::BufferNullPointer, null());
833833
let style_sheet_import_index = raw_ptr_as_mut_ref!(this, StyleSheetImportIndex);
834-
let bincode: *mut [u8] = core::slice::from_raw_parts_mut(buffer_ptr, buffer_len);
834+
let bincode: *mut [u8] = core::ptr::slice_from_raw_parts_mut(buffer_ptr, buffer_len);
835835
style_sheet_import_index
836836
.inner
837837
.merge_bincode_zero_copy(bincode, move || {
@@ -858,7 +858,7 @@ pub unsafe extern "C" fn style_sheet_import_index_merge_bincode(
858858
#[export_name = "FPBufferFree"]
859859
pub unsafe extern "C" fn buffer_free(buffer_ptr: *mut u8, buffer_len: usize) -> FfiResult<NullPtr> {
860860
check_null!(buffer_ptr, FfiErrorCode::BufferNullPointer, null());
861-
let x: *mut [u8] = core::slice::from_raw_parts_mut(buffer_ptr, buffer_len);
861+
let x: *mut [u8] = core::ptr::slice_from_raw_parts_mut(buffer_ptr, buffer_len);
862862
drop(Box::from_raw(x));
863863
FfiResult::ok(null())
864864
}
@@ -1088,7 +1088,7 @@ pub unsafe extern "C" fn style_sheet_bincode_version(
10881088
use float_pigment_consistent_bincode::Options;
10891089
check_null!(buffer_ptr, FfiErrorCode::BufferNullPointer, null_mut());
10901090
let sheet = de_static_ref_zero_copy_env(
1091-
core::slice::from_raw_parts_mut(buffer_ptr, buffer_len),
1091+
core::ptr::slice_from_raw_parts_mut(buffer_ptr, buffer_len),
10921092
|s| {
10931093
let s: Result<StyleSheet, _> = float_pigment_consistent_bincode::DefaultOptions::new()
10941094
.allow_trailing_bytes()
@@ -1098,10 +1098,8 @@ pub unsafe extern "C" fn style_sheet_bincode_version(
10981098
Err(err) => {
10991099
let mut ss = StyleSheet::from_sheet(&sheet::CompiledStyleSheet::new());
11001100
if let StyleSheet::V1(ssv) = &mut ss {
1101-
ssv.version = Box::new(
1102-
format!("Failed to deserialize bincode formatted style sheet: {err}")
1103-
.into(),
1104-
);
1101+
*ssv.version = format!("Failed to deserialize bincode formatted style sheet: {err}")
1102+
.into();
11051103
}
11061104
ss
11071105
}

float-pigment-css/src/parser/property_value/gradient.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ fn gradient_position_repr<'a, 't: 'a, 'i: 't>(
822822
// hit <length-percentage>
823823
return Ok(GradientPosition::Pos(parsed_length, Length::Ratio(0.5)));
824824
}
825-
return Err(parser.new_custom_error(CustomError::Unsupported));
825+
Err(parser.new_custom_error(CustomError::Unsupported))
826826
});
827827

828828
if parse_position_one_res.is_ok() && (!strict || parser.is_exhausted()) {

float-pigment-css/src/typing.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,18 +298,14 @@ impl Length {
298298
#[repr(C)]
299299
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ResolveFontSize)]
300300
#[cfg_attr(debug_assertions, derive(CompatibilityEnumCheck))]
301+
#[derive(Default)]
301302
pub enum LengthExpr {
303+
#[default]
302304
Invalid,
303305
Env(StrRef, Box<Length>),
304306
Calc(Box<CalcExpr>),
305307
}
306308

307-
impl Default for LengthExpr {
308-
fn default() -> Self {
309-
Self::Invalid
310-
}
311-
}
312-
313309
impl CalcExpr {
314310
fn resolve_to_f32<L: LengthNum>(
315311
&self,

float-pigment-layout/src/algo/grid/matrix.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ impl OccupiedBitmap {
5656
fn new(stride: usize, row_order: bool, capacity: usize) -> Self {
5757
debug_assert!(stride >= 1);
5858
let stride: usize = stride.max(1);
59-
let bytes_per_line = (stride + 7) / 8;
59+
let bytes_per_line = stride.div_ceil(8);
6060
let estimated_lines = if stride > 0 {
61-
(capacity + stride - 1) / stride
61+
capacity.div_ceil(stride)
6262
} else {
6363
0
6464
};
@@ -129,7 +129,7 @@ impl OccupiedBitmap {
129129
debug_assert!(new_stride > self.stride, "stride can only grow");
130130
let new_stride: usize = new_stride.max(1);
131131
let old_bytes_per_line = self.bytes_per_line;
132-
let new_bytes_per_line = (new_stride + 7) / 8;
132+
let new_bytes_per_line = new_stride.div_ceil(8);
133133
let new_total_bytes = max_lines * new_bytes_per_line;
134134

135135
self.bits.resize(new_total_bytes, 0u8);
@@ -224,7 +224,7 @@ pub(crate) struct GridMatrix<'a, T: LayoutTreeNode> {
224224
flow: GridAutoFlow,
225225
}
226226

227-
impl<'a, 'b: 'a, T: LayoutTreeNode> GridMatrix<'a, T> {
227+
impl<'a, T: LayoutTreeNode> GridMatrix<'a, T> {
228228
/// Create a new empty grid matrix.
229229
///
230230
/// The grid starts empty and expands dynamically when items are placed.

float-pigment-layout/src/types.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,10 @@ impl<L: LengthNum> VectorProxy<L> for Vector<L> {
175175

176176
/// A length type that can be undefined or auto.
177177
#[derive(Debug, Clone, Copy, PartialEq)]
178+
#[derive(Default)]
178179
pub enum DefLength<L: LengthNum, T: PartialEq + Clone = i32> {
179180
/// The length is undetermined.
181+
#[default]
180182
Undefined,
181183

182184
/// The length is auto.
@@ -206,11 +208,6 @@ impl<L: LengthNum, T: PartialEq + Display + Clone> Display for DefLength<L, T> {
206208
}
207209
}
208210

209-
impl<L: LengthNum, T: PartialEq + Clone> Default for DefLength<L, T> {
210-
fn default() -> Self {
211-
Self::Undefined
212-
}
213-
}
214211

215212
impl<L: LengthNum, T: PartialEq + Clone> DefLength<L, T> {
216213
pub(crate) fn resolve<N: LayoutTreeNode<Length = L, LengthCustom = T>>(
@@ -831,7 +828,6 @@ impl AxisInfo {
831828
}
832829

833830
/// Create AxisInfo considering both writing-mode and direction.
834-
835831
pub(crate) fn from_writing_mode_and_direction(
836832
writing_mode: WritingMode,
837833
direction: Direction,
@@ -1041,16 +1037,13 @@ pub(crate) fn size_to_option<L: LengthNum>(size: Size<L>) -> OptionSize<L> {
10411037

10421038
#[allow(missing_docs)]
10431039
#[derive(Debug, Clone, PartialEq)]
1040+
#[derive(Default)]
10441041
pub enum LayoutGridTemplate<L: LengthNum, T: PartialEq + Clone = i32> {
1042+
#[default]
10451043
None,
10461044
TrackList(Vec<LayoutTrackListItem<L, T>>),
10471045
}
10481046

1049-
impl<L: LengthNum, T: PartialEq + Clone> Default for LayoutGridTemplate<L, T> {
1050-
fn default() -> Self {
1051-
Self::None
1052-
}
1053-
}
10541047

10551048
#[allow(missing_docs)]
10561049
#[derive(Debug, Clone, PartialEq)]

0 commit comments

Comments
 (0)