Improve Au(0) constructions (#33709)

This replaces `Au(0)` with `Au::zero()` and other utility functions when possible.

Signed-off-by: hackerbirds <120066692+hackerbirds@users.noreply.github.com>
This commit is contained in:
birdbrained 2024-10-10 16:45:18 +00:00 committed by GitHub
parent c6d305fbb3
commit a591778a25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 20 additions and 16 deletions

1
Cargo.lock generated
View file

@ -2050,6 +2050,7 @@ dependencies = [
"malloc_size_of", "malloc_size_of",
"malloc_size_of_derive", "malloc_size_of_derive",
"net_traits", "net_traits",
"num-traits",
"parking_lot", "parking_lot",
"range", "range",
"serde", "serde",

View file

@ -32,6 +32,7 @@ log = { workspace = true }
malloc_size_of = { workspace = true } malloc_size_of = { workspace = true }
malloc_size_of_derive = { workspace = true } malloc_size_of_derive = { workspace = true }
net_traits = { workspace = true } net_traits = { workspace = true }
num-traits = { workspace = true }
parking_lot = { workspace = true } parking_lot = { workspace = true }
range = { path = "../range" } range = { path = "../range" }
serde = { workspace = true } serde = { workspace = true }

View file

@ -441,7 +441,7 @@ impl Font {
let offset = prev_glyph_id.map(|prev| { let offset = prev_glyph_id.map(|prev| {
let h_kerning = Au::from_f64_px(self.glyph_h_kerning(prev, glyph_id)); let h_kerning = Au::from_f64_px(self.glyph_h_kerning(prev, glyph_id));
advance += h_kerning; advance += h_kerning;
Point2D::new(h_kerning, Au(0)) Point2D::new(h_kerning, Au::zero())
}); });
let glyph = GlyphData::new(glyph_id, advance, offset, true, true); let glyph = GlyphData::new(glyph_id, advance, offset, true, true);
@ -818,7 +818,7 @@ pub struct RunMetrics {
impl RunMetrics { impl RunMetrics {
pub fn new(advance: Au, ascent: Au, descent: Au) -> RunMetrics { pub fn new(advance: Au, ascent: Au, descent: Au) -> RunMetrics {
let bounds = Rect::new( let bounds = Rect::new(
Point2D::new(Au(0), -ascent), Point2D::new(Au::zero(), -ascent),
Size2D::new(advance, ascent + descent), Size2D::new(advance, ascent + descent),
); );

View file

@ -10,6 +10,7 @@ use std::{fmt, mem};
use app_units::Au; use app_units::Au;
use euclid::default::Point2D; use euclid::default::Point2D;
use euclid::num::Zero;
pub use fonts_traits::ByteIndex; pub use fonts_traits::ByteIndex;
use itertools::Either; use itertools::Either;
use log::debug; use log::debug;
@ -97,7 +98,7 @@ fn is_simple_glyph_id(id: GlyphId) -> bool {
} }
fn is_simple_advance(advance: Au) -> bool { fn is_simple_advance(advance: Au) -> bool {
advance >= Au(0) && { advance >= Au::zero() && {
let unsigned_au = advance.0 as u32; let unsigned_au = advance.0 as u32;
(unsigned_au & (GLYPH_ADVANCE_MASK >> GLYPH_ADVANCE_SHIFT)) == unsigned_au (unsigned_au & (GLYPH_ADVANCE_MASK >> GLYPH_ADVANCE_SHIFT)) == unsigned_au
} }
@ -474,7 +475,7 @@ impl GlyphStore {
GlyphStore { GlyphStore {
entry_buffer: vec![GlyphEntry::initial(); length], entry_buffer: vec![GlyphEntry::initial(); length],
detail_store: DetailedGlyphStore::new(), detail_store: DetailedGlyphStore::new(),
total_advance: Au(0), total_advance: Au::zero(),
total_word_separators: 0, total_word_separators: 0,
has_detailed_glyphs: false, has_detailed_glyphs: false,
is_whitespace, is_whitespace,
@ -516,7 +517,7 @@ impl GlyphStore {
#[inline(never)] #[inline(never)]
fn cache_total_advance_and_word_separators(&mut self) { fn cache_total_advance_and_word_separators(&mut self) {
let mut total_advance = Au(0); let mut total_advance = Au::zero();
let mut total_word_separators = 0; let mut total_word_separators = 0;
for glyph in self.iter_glyphs_for_byte_range(&Range::new(ByteIndex(0), self.len())) { for glyph in self.iter_glyphs_for_byte_range(&Range::new(ByteIndex(0), self.len())) {
total_advance += glyph.advance(); total_advance += glyph.advance();
@ -651,7 +652,7 @@ impl GlyphStore {
extra_word_spacing: Au, extra_word_spacing: Au,
) -> (usize, Au) { ) -> (usize, Au) {
let mut index = 0; let mut index = 0;
let mut current_advance = Au(0); let mut current_advance = Au::zero();
for glyph in self.iter_glyphs_for_byte_range(range) { for glyph in self.iter_glyphs_for_byte_range(range) {
if glyph.char_is_word_separator() { if glyph.char_is_word_separator() {
current_advance += glyph.advance() + extra_word_spacing current_advance += glyph.advance() + extra_word_spacing
@ -682,7 +683,7 @@ impl GlyphStore {
extra_word_spacing: Au, extra_word_spacing: Au,
) -> Au { ) -> Au {
self.iter_glyphs_for_byte_range(range) self.iter_glyphs_for_byte_range(range)
.fold(Au(0), |advance, glyph| { .fold(Au::zero(), |advance, glyph| {
if glyph.char_is_word_separator() { if glyph.char_is_word_separator() {
advance + glyph.advance() + extra_word_spacing advance + glyph.advance() + extra_word_spacing
} else { } else {

View file

@ -26,6 +26,7 @@ use harfbuzz_sys::{
HB_OT_LAYOUT_BASELINE_TAG_ROMAN, HB_OT_LAYOUT_BASELINE_TAG_ROMAN,
}; };
use log::debug; use log::debug;
use num_traits::Zero;
use crate::platform::font::FontTable; use crate::platform::font::FontTable;
use crate::{ use crate::{
@ -107,11 +108,11 @@ impl ShapedGlyphData {
let x_advance = Au::from_f64_px(x_advance); let x_advance = Au::from_f64_px(x_advance);
let y_advance = Au::from_f64_px(y_advance); let y_advance = Au::from_f64_px(y_advance);
let offset = if x_offset == Au(0) && y_offset == Au(0) && y_advance == Au(0) { let offset = if x_offset.is_zero() && y_offset.is_zero() && y_advance.is_zero() {
None None
} else { } else {
// adjust the pen.. // adjust the pen..
if y_advance > Au(0) { if y_advance > Au::zero() {
*y_pos -= y_advance; *y_pos -= y_advance;
} }
@ -466,7 +467,7 @@ impl Shaper {
let mut glyph_span = 0..0; let mut glyph_span = 0..0;
let mut byte_range = 0..0; let mut byte_range = 0..0;
let mut y_pos = Au(0); let mut y_pos = Au::zero();
// main loop over each glyph. each iteration usually processes 1 glyph and 1+ chars. // main loop over each glyph. each iteration usually processes 1 glyph and 1+ chars.
// in cases with complex glyph-character associations, 2+ glyphs and 1+ chars can be // in cases with complex glyph-character associations, 2+ glyphs and 1+ chars can be

View file

@ -1041,10 +1041,10 @@ impl<'a> TableLayout<'a> {
|column_index: &usize| self.column_measures[*column_index].percentage.0 > 0.; |column_index: &usize| self.column_measures[*column_index].percentage.0 > 0.;
let has_percent_zero = |column_index: &usize| !has_percent_greater_than_zero(column_index); let has_percent_zero = |column_index: &usize| !has_percent_greater_than_zero(column_index);
let has_max_content = |column_index: &usize| { let has_max_content = |column_index: &usize| {
self.column_measures[*column_index] !self.column_measures[*column_index]
.content_sizes .content_sizes
.max_content != .max_content
Au(0) .is_zero()
}; };
let max_content_sum = let max_content_sum =
@ -2862,8 +2862,8 @@ fn get_outer_sizes_for_measurement(
let min_size = style.min_box_size(writing_mode); let min_size = style.min_box_size(writing_mode);
let max_size = style.max_box_size(writing_mode); let max_size = style.max_box_size(writing_mode);
( (
outer_size(size.map(|v| get_size_for_axis(v).unwrap_or(Au(0)))), outer_size(size.map(|v| get_size_for_axis(v).unwrap_or_else(Au::zero))),
outer_size(min_size.map(|v| get_size_for_axis(v).unwrap_or(Au(0)))), outer_size(min_size.map(|v| get_size_for_axis(v).unwrap_or_else(Au::zero))),
outer_size(max_size.map(|v| get_size_for_axis(v).unwrap_or(MAX_AU))), outer_size(max_size.map(|v| get_size_for_axis(v).unwrap_or(MAX_AU))),
size.inline.is_keyword(), size.inline.is_keyword(),
get_size_percentage_contribution(&size, &max_size), get_size_percentage_contribution(&size, &max_size),

View file

@ -875,7 +875,7 @@ impl LayoutThread {
root_flow.overflow.scroll.size root_flow.overflow.scroll.size
}; };
let origin = Rect::new(Point2D::new(Au(0), Au(0)), root_size).to_layout(); let origin = Rect::new(Point2D::zero(), root_size).to_layout();
build_state.root_stacking_context.bounds = origin; build_state.root_stacking_context.bounds = origin;
build_state.root_stacking_context.overflow = origin; build_state.root_stacking_context.overflow = origin;