mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
refactor: use is_zero() instead of comparing with Au::Zero() (#36347)
Use `is_zero()` instead of comparing with `Au::Zero()` for zero checks. Testing: This change does not cause behaviour change, a test is not necessary. Fixes: #36300 --------- Signed-off-by: Barigbue <barigbuenbira@gmail.com>
This commit is contained in:
parent
2fe57cc2a2
commit
a0730d7154
7 changed files with 16 additions and 14 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -4204,6 +4204,7 @@ dependencies = [
|
||||||
"itertools 0.13.0",
|
"itertools 0.13.0",
|
||||||
"log",
|
"log",
|
||||||
"net_traits",
|
"net_traits",
|
||||||
|
"num-traits",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"pixels",
|
"pixels",
|
||||||
"quickcheck",
|
"quickcheck",
|
||||||
|
|
|
@ -58,4 +58,5 @@ webrender_api = { workspace = true }
|
||||||
xi-unicode = { workspace = true }
|
xi-unicode = { workspace = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
num-traits = { workspace = true }
|
||||||
quickcheck = "1"
|
quickcheck = "1"
|
||||||
|
|
|
@ -1071,7 +1071,7 @@ fn allocate_free_cross_space_for_flex_line(
|
||||||
remaining_free_cross_space: Au,
|
remaining_free_cross_space: Au,
|
||||||
remaining_line_count: i32,
|
remaining_line_count: i32,
|
||||||
) -> (Au, Au) {
|
) -> (Au, Au) {
|
||||||
if remaining_free_cross_space == Au::zero() {
|
if remaining_free_cross_space.is_zero() {
|
||||||
return (Au::zero(), Au::zero());
|
return (Au::zero(), Au::zero());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1394,7 +1394,7 @@ impl InitialFlexLineLayout<'_> {
|
||||||
//
|
//
|
||||||
// FIXME: is it a problem if floating point precision errors accumulate
|
// FIXME: is it a problem if floating point precision errors accumulate
|
||||||
// and we get not-quite-zero remaining free space when we should get zero here?
|
// and we get not-quite-zero remaining free space when we should get zero here?
|
||||||
if remaining_free_space != Au::zero() {
|
if !remaining_free_space.is_zero() {
|
||||||
// > If using the flex grow factor:
|
// > If using the flex grow factor:
|
||||||
// > For every unfrozen item on the line, find the ratio of the item’s flex grow factor to
|
// > For every unfrozen item on the line, find the ratio of the item’s flex grow factor to
|
||||||
// > the sum of the flex grow factors of all unfrozen items on the line. Set the item’s
|
// > the sum of the flex grow factors of all unfrozen items on the line. Set the item’s
|
||||||
|
|
|
@ -1720,7 +1720,7 @@ impl InlineFormattingContext {
|
||||||
let mut collapsible_margins_in_children = CollapsedBlockMargins::zero();
|
let mut collapsible_margins_in_children = CollapsedBlockMargins::zero();
|
||||||
let content_block_size = layout.current_line.start_position.block;
|
let content_block_size = layout.current_line.start_position.block;
|
||||||
collapsible_margins_in_children.collapsed_through = !layout.had_inflow_content &&
|
collapsible_margins_in_children.collapsed_through = !layout.had_inflow_content &&
|
||||||
content_block_size == Au::zero() &&
|
content_block_size.is_zero() &&
|
||||||
collapsible_with_parent_start_margin.0;
|
collapsible_with_parent_start_margin.0;
|
||||||
|
|
||||||
CacheableLayoutResult {
|
CacheableLayoutResult {
|
||||||
|
|
|
@ -162,7 +162,7 @@ impl BlockLevelBox {
|
||||||
_ => return false,
|
_ => return false,
|
||||||
};
|
};
|
||||||
|
|
||||||
if pbm.padding.block_start != Au::zero() || pbm.border.block_start != Au::zero() {
|
if !pbm.padding.block_start.is_zero() || !pbm.border.block_start.is_zero() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ impl BlockLevelBox {
|
||||||
|
|
||||||
if !block_size_is_zero_or_intrinsic(style.content_block_size(), containing_block) ||
|
if !block_size_is_zero_or_intrinsic(style.content_block_size(), containing_block) ||
|
||||||
!block_size_is_zero_or_intrinsic(style.min_block_size(), containing_block) ||
|
!block_size_is_zero_or_intrinsic(style.min_block_size(), containing_block) ||
|
||||||
pbm.padding_border_sums.block != Au::zero()
|
!pbm.padding_border_sums.block.is_zero()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -907,7 +907,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context(
|
||||||
|
|
||||||
let computed_block_size = style.content_block_size();
|
let computed_block_size = style.content_block_size();
|
||||||
let start_margin_can_collapse_with_children =
|
let start_margin_can_collapse_with_children =
|
||||||
pbm.padding.block_start == Au::zero() && pbm.border.block_start == Au::zero();
|
pbm.padding.block_start.is_zero() && pbm.border.block_start.is_zero();
|
||||||
|
|
||||||
let mut clearance = None;
|
let mut clearance = None;
|
||||||
let parent_containing_block_position_info;
|
let parent_containing_block_position_info;
|
||||||
|
@ -1024,14 +1024,14 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context(
|
||||||
}
|
}
|
||||||
|
|
||||||
let collapsed_through = collapsible_margins_in_children.collapsed_through &&
|
let collapsed_through = collapsible_margins_in_children.collapsed_through &&
|
||||||
pbm.padding_border_sums.block == Au::zero() &&
|
pbm.padding_border_sums.block.is_zero() &&
|
||||||
block_size_is_zero_or_intrinsic(computed_block_size, containing_block) &&
|
block_size_is_zero_or_intrinsic(computed_block_size, containing_block) &&
|
||||||
block_size_is_zero_or_intrinsic(style.min_block_size(), containing_block);
|
block_size_is_zero_or_intrinsic(style.min_block_size(), containing_block);
|
||||||
block_margins_collapsed_with_children.collapsed_through = collapsed_through;
|
block_margins_collapsed_with_children.collapsed_through = collapsed_through;
|
||||||
|
|
||||||
let end_margin_can_collapse_with_children = collapsed_through ||
|
let end_margin_can_collapse_with_children = collapsed_through ||
|
||||||
(pbm.padding.block_end == Au::zero() &&
|
(pbm.padding.block_end.is_zero() &&
|
||||||
pbm.border.block_end == Au::zero() &&
|
pbm.border.block_end.is_zero() &&
|
||||||
!containing_block_for_children.size.block.is_definite());
|
!containing_block_for_children.size.block.is_definite());
|
||||||
if end_margin_can_collapse_with_children {
|
if end_margin_can_collapse_with_children {
|
||||||
block_margins_collapsed_with_children
|
block_margins_collapsed_with_children
|
||||||
|
|
|
@ -960,7 +960,7 @@ impl<'a> TableLayout<'a> {
|
||||||
.clone()
|
.clone()
|
||||||
.map(max_content_sum)
|
.map(max_content_sum)
|
||||||
.fold(Au::zero(), |a, b| a + b);
|
.fold(Au::zero(), |a, b| a + b);
|
||||||
if total_max_content_width != Au::zero() {
|
if !total_max_content_width.is_zero() {
|
||||||
for column_index in unconstrained_max_content_columns {
|
for column_index in unconstrained_max_content_columns {
|
||||||
column_sizes[column_index] += extra_inline_size.scale_by(
|
column_sizes[column_index] += extra_inline_size.scale_by(
|
||||||
columns[column_index].content_sizes.max_content.to_f32_px() /
|
columns[column_index].content_sizes.max_content.to_f32_px() /
|
||||||
|
@ -1005,7 +1005,7 @@ impl<'a> TableLayout<'a> {
|
||||||
.clone()
|
.clone()
|
||||||
.map(max_content_sum)
|
.map(max_content_sum)
|
||||||
.fold(Au::zero(), |a, b| a + b);
|
.fold(Au::zero(), |a, b| a + b);
|
||||||
if total_max_content_width != Au::zero() {
|
if !total_max_content_width.is_zero() {
|
||||||
for column_index in constrained_max_content_columns {
|
for column_index in constrained_max_content_columns {
|
||||||
column_sizes[column_index] += extra_inline_size.scale_by(
|
column_sizes[column_index] += extra_inline_size.scale_by(
|
||||||
columns[column_index].content_sizes.max_content.to_f32_px() /
|
columns[column_index].content_sizes.max_content.to_f32_px() /
|
||||||
|
|
|
@ -11,12 +11,12 @@ use std::sync::{Mutex, MutexGuard};
|
||||||
use std::{thread, u32};
|
use std::{thread, u32};
|
||||||
|
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use euclid::num::Zero;
|
|
||||||
use layout_2020::flow::float::{
|
use layout_2020::flow::float::{
|
||||||
Clear, ContainingBlockPositionInfo, FloatBand, FloatBandNode, FloatBandTree, FloatContext,
|
Clear, ContainingBlockPositionInfo, FloatBand, FloatBandNode, FloatBandTree, FloatContext,
|
||||||
FloatSide, PlacementInfo,
|
FloatSide, PlacementInfo,
|
||||||
};
|
};
|
||||||
use layout_2020::geom::{LogicalRect, LogicalVec2};
|
use layout_2020::geom::{LogicalRect, LogicalVec2};
|
||||||
|
use num_traits::identities::Zero;
|
||||||
use quickcheck::{Arbitrary, Gen};
|
use quickcheck::{Arbitrary, Gen};
|
||||||
|
|
||||||
static PANIC_HOOK_MUTEX: Mutex<()> = Mutex::new(());
|
static PANIC_HOOK_MUTEX: Mutex<()> = Mutex::new(());
|
||||||
|
@ -559,7 +559,7 @@ fn check_floats_rule_3(placement: &FloatPlacement) {
|
||||||
// Where the top of `b` should probably be 32px per Rule 3, but unless this distinction
|
// Where the top of `b` should probably be 32px per Rule 3, but unless this distinction
|
||||||
// is made the top of `b` could legally be 0px.
|
// is made the top of `b` could legally be 0px.
|
||||||
if this_float.origin.block >= other_float.rect().max_block_position() ||
|
if this_float.origin.block >= other_float.rect().max_block_position() ||
|
||||||
(this_float.info.size.block == Au::zero() &&
|
(this_float.info.size.block.is_zero() &&
|
||||||
this_float.rect().max_block_position() < other_float.origin.block) ||
|
this_float.rect().max_block_position() < other_float.origin.block) ||
|
||||||
(this_float.info.size.block > Au::zero() &&
|
(this_float.info.size.block > Au::zero() &&
|
||||||
this_float.rect().max_block_position() <= other_float.origin.block)
|
this_float.rect().max_block_position() <= other_float.origin.block)
|
||||||
|
@ -729,7 +729,7 @@ fn check_floats_rule_10(placement: &FloatPlacement) {
|
||||||
// Where the top of `b` should probably be 32px per Rule 3, but unless this distinction
|
// Where the top of `b` should probably be 32px per Rule 3, but unless this distinction
|
||||||
// is made the top of `b` could legally be 0px.
|
// is made the top of `b` could legally be 0px.
|
||||||
if this_float.origin.block >= other_float.rect().max_block_position() ||
|
if this_float.origin.block >= other_float.rect().max_block_position() ||
|
||||||
(this_float.info.size.block == Au::zero() &&
|
(this_float.info.size.block.is_zero() &&
|
||||||
this_float.rect().max_block_position() < other_float.origin.block) ||
|
this_float.rect().max_block_position() < other_float.origin.block) ||
|
||||||
(this_float.info.size.block > Au::zero() &&
|
(this_float.info.size.block > Au::zero() &&
|
||||||
this_float.rect().max_block_position() <= other_float.origin.block)
|
this_float.rect().max_block_position() <= other_float.origin.block)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue