Repository: servo/servo
File: components/layout/fragment_tree/fragment.rs (Rust)

Code before:
            self.glyphs
                .iter()
                .map(|glyph_store| glyph_store.glyph_count())
                .sum::<usize>(),
            self.base.rect
        ));
    }

    pub fn has_selection(&self) -> bool {
        self.selection_range.is_some()
    }

    pub(crate) fn glyph_offset(&self, point_in_parent: Point2D<Au, CSSPixel>) -> usize {
        let point = point_in_parent - self.base.rect.origin;
        let mut current_glyph = self.starting_glyph_offset;
        let mut current_offset = Au::zero();

        for glyph_store in &self.glyphs {
            for glyph in glyph_store.iter_glyphs_for_byte_range(TextByteRange::new(
                ByteIndex::zero(),
                glyph_store.len(),
            )) {
                current_offset += glyph.advance();
                if current_offset - (glyph.advance().scale_by(0.5)) >= point.x {
                    return current_glyph;
                }

                current_glyph += 1;
            }
        }

        current_glyph
    }
}

impl ImageFragment {
    pub fn print(&self, tree: &mut PrintTree) {
        tree.add_item(format!(
            "Image\
                \nrect={:?}",
            self.base.rect
        ));
    }
}

impl IFrameFragment {
    pub fn print(&self, tree: &mut PrintTree) {
        tree.add_item(format!(
            "IFrame\
                \npipeline={:?} rect={:?}",
            self.pipeline_id, self.base.rect

Review comment (suggestion):
Can avoid calling `glyph.advance()` twice, and I think it looks better by increasing afterwards instead of subtracting in the condition

```suggestion
                let advance = glyph.advance();
                if current_offset + advance.scale_by(0.5) >= point.x {
                    return current_glyph;
                }
                current_offset += advance;
```

Code after:
            self.glyphs
                .iter()
                .map(|glyph_store| glyph_store.glyph_count())
                .sum::<usize>(),
            self.base.rect
        ));
    }

    pub fn has_selection(&self) -> bool {
        self.selection_range.is_some()
    }

    pub(crate) fn glyph_offset(&self, point_in_parent: Point2D<Au, CSSPixel>) -> usize {
        let point = point_in_parent - self.base.rect.origin;
        let mut current_glyph = self.starting_glyph_offset;
        let mut current_offset = Au::zero();

        for glyph_store in &self.glyphs {
            for glyph in glyph_store.iter_glyphs_for_byte_range(TextByteRange::new(
                ByteIndex::zero(),
                glyph_store.len(),
            )) {
                let advance = glyph.advance();
                if current_offset + advance.scale_by(0.5) >= point.x {
                    return current_glyph;
                }
                current_offset += advance;
                current_glyph += 1;
            }
        }

        current_glyph
    }
}

impl ImageFragment {
    pub fn print(&self, tree: &mut PrintTree) {
        tree.add_item(format!(
            "Image\
                \nrect={:?}",
            self.base.rect
        ));
    }
}

impl IFrameFragment {
    pub fn print(&self, tree: &mut PrintTree) {
        tree.add_item(format!(
            "IFrame\
                \npipeline={:?} rect={:?}",
            self.pipeline_id, self.base.rect