aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBarigbue Nbira <barigbuenbira@gmail.com>2025-04-09 23:57:55 +0100
committerGitHub <noreply@github.com>2025-04-09 22:57:55 +0000
commita0730d7154e183a9b2d9a9282061e6c67d87a263 (patch)
tree2ee915d3b08a0b8a2ed1879132cd8a110d0cbf97
parent2fe57cc2a2e5e7b982f7a32349117e2516724682 (diff)
downloadservo-a0730d7154e183a9b2d9a9282061e6c67d87a263.tar.gz
servo-a0730d7154e183a9b2d9a9282061e6c67d87a263.zip
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>
-rw-r--r--Cargo.lock1
-rw-r--r--components/layout_2020/Cargo.toml1
-rw-r--r--components/layout_2020/flexbox/layout.rs4
-rw-r--r--components/layout_2020/flow/inline/mod.rs2
-rw-r--r--components/layout_2020/flow/mod.rs12
-rw-r--r--components/layout_2020/table/layout.rs4
-rw-r--r--components/layout_2020/tests/floats.rs6
7 files changed, 16 insertions, 14 deletions
diff --git a/Cargo.lock b/Cargo.lock
index d6489e9b799..8cd186bcb94 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4204,6 +4204,7 @@ dependencies = [
"itertools 0.13.0",
"log",
"net_traits",
+ "num-traits",
"parking_lot",
"pixels",
"quickcheck",
diff --git a/components/layout_2020/Cargo.toml b/components/layout_2020/Cargo.toml
index 30fb8843d67..8739f66f4e9 100644
--- a/components/layout_2020/Cargo.toml
+++ b/components/layout_2020/Cargo.toml
@@ -58,4 +58,5 @@ webrender_api = { workspace = true }
xi-unicode = { workspace = true }
[dev-dependencies]
+num-traits = { workspace = true }
quickcheck = "1"
diff --git a/components/layout_2020/flexbox/layout.rs b/components/layout_2020/flexbox/layout.rs
index 4720b5f9d74..55fa5a173b0 100644
--- a/components/layout_2020/flexbox/layout.rs
+++ b/components/layout_2020/flexbox/layout.rs
@@ -1071,7 +1071,7 @@ fn allocate_free_cross_space_for_flex_line(
remaining_free_cross_space: Au,
remaining_line_count: i32,
) -> (Au, Au) {
- if remaining_free_cross_space == Au::zero() {
+ if remaining_free_cross_space.is_zero() {
return (Au::zero(), Au::zero());
}
@@ -1394,7 +1394,7 @@ impl InitialFlexLineLayout<'_> {
//
// 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?
- if remaining_free_space != Au::zero() {
+ if !remaining_free_space.is_zero() {
// > If using the flex grow factor:
// > 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
diff --git a/components/layout_2020/flow/inline/mod.rs b/components/layout_2020/flow/inline/mod.rs
index ec77842854a..ee22830aa9e 100644
--- a/components/layout_2020/flow/inline/mod.rs
+++ b/components/layout_2020/flow/inline/mod.rs
@@ -1720,7 +1720,7 @@ impl InlineFormattingContext {
let mut collapsible_margins_in_children = CollapsedBlockMargins::zero();
let content_block_size = layout.current_line.start_position.block;
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;
CacheableLayoutResult {
diff --git a/components/layout_2020/flow/mod.rs b/components/layout_2020/flow/mod.rs
index 8ddbddee507..aa4bf8dd36f 100644
--- a/components/layout_2020/flow/mod.rs
+++ b/components/layout_2020/flow/mod.rs
@@ -162,7 +162,7 @@ impl BlockLevelBox {
_ => 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;
}
@@ -215,7 +215,7 @@ impl BlockLevelBox {
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) ||
- pbm.padding_border_sums.block != Au::zero()
+ !pbm.padding_border_sums.block.is_zero()
{
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 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 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 &&
- 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(style.min_block_size(), containing_block);
block_margins_collapsed_with_children.collapsed_through = collapsed_through;
let end_margin_can_collapse_with_children = collapsed_through ||
- (pbm.padding.block_end == Au::zero() &&
- pbm.border.block_end == Au::zero() &&
+ (pbm.padding.block_end.is_zero() &&
+ pbm.border.block_end.is_zero() &&
!containing_block_for_children.size.block.is_definite());
if end_margin_can_collapse_with_children {
block_margins_collapsed_with_children
diff --git a/components/layout_2020/table/layout.rs b/components/layout_2020/table/layout.rs
index ed35cff6049..e01f1cbabf0 100644
--- a/components/layout_2020/table/layout.rs
+++ b/components/layout_2020/table/layout.rs
@@ -960,7 +960,7 @@ impl<'a> TableLayout<'a> {
.clone()
.map(max_content_sum)
.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 {
column_sizes[column_index] += extra_inline_size.scale_by(
columns[column_index].content_sizes.max_content.to_f32_px() /
@@ -1005,7 +1005,7 @@ impl<'a> TableLayout<'a> {
.clone()
.map(max_content_sum)
.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 {
column_sizes[column_index] += extra_inline_size.scale_by(
columns[column_index].content_sizes.max_content.to_f32_px() /
diff --git a/components/layout_2020/tests/floats.rs b/components/layout_2020/tests/floats.rs
index 8c5cd019a0c..9cf8df6ecfb 100644
--- a/components/layout_2020/tests/floats.rs
+++ b/components/layout_2020/tests/floats.rs
@@ -11,12 +11,12 @@ use std::sync::{Mutex, MutexGuard};
use std::{thread, u32};
use app_units::Au;
-use euclid::num::Zero;
use layout_2020::flow::float::{
Clear, ContainingBlockPositionInfo, FloatBand, FloatBandNode, FloatBandTree, FloatContext,
FloatSide, PlacementInfo,
};
use layout_2020::geom::{LogicalRect, LogicalVec2};
+use num_traits::identities::Zero;
use quickcheck::{Arbitrary, Gen};
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
// is made the top of `b` could legally be 0px.
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.info.size.block > Au::zero() &&
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
// is made the top of `b` could legally be 0px.
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.info.size.block > Au::zero() &&
this_float.rect().max_block_position() <= other_float.origin.block)