Repository: servo/servo
File: components/shared/layout/layout_damage.rs (Rust)

Code before:
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use bitflags::bitflags;
use style::selector_parser::RestyleDamage;

bitflags! {
    /// Individual layout actions that may be necessary after restyling. This is an extension
    /// of `RestyleDamage` from stylo, which only uses the 4 lower bits.
    #[derive(Clone, Copy, Default, Eq, PartialEq)]
    pub struct LayoutDamage: u16 {
        /// Recollect the box children for this element, because some of the them will be
        /// rebuilt.
        const RECOLLECT_BOX_TREE_CHILDREN = 0b0111_1111_1111 << 4;
        /// Clear the cached inline content sizes.
        const RECOMPUTE_INLINE_CONTENT_SIZES = 0b1000_0000_0000 << 4;
        /// Rebuild the entire box for this element, which means that every part of layout
        /// needs to happen again.
        const REBUILD_BOX = 0b1111_1111_1111 << 4;
    }
}

impl LayoutDamage {
    pub fn recollect_box_tree_children() -> RestyleDamage {
        RestyleDamage::from_bits_retain(LayoutDamage::RECOLLECT_BOX_TREE_CHILDREN.bits())
    }

    pub fn recompute_inline_content_sizes() -> RestyleDamage {
        RestyleDamage::from_bits_retain(LayoutDamage::RECOMPUTE_INLINE_CONTENT_SIZES.bits())
    }

    pub fn rebuild_box_tree() -> RestyleDamage {
        RestyleDamage::from_bits_retain(LayoutDamage::REBUILD_BOX.bits())
    }

    pub fn has_box_damage(&self) -> bool {
        self.intersects(Self::REBUILD_BOX)
    }
}


Review comment (performance):
```suggestion
        /// Clear the cached inline content sizes and recompute them during the next layout.
```

Code after:
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use bitflags::bitflags;
use style::selector_parser::RestyleDamage;

bitflags! {
    /// Individual layout actions that may be necessary after restyling. This is an extension
    /// of `RestyleDamage` from stylo, which only uses the 4 lower bits.
    #[derive(Clone, Copy, Default, Eq, PartialEq)]
    pub struct LayoutDamage: u16 {
        /// Recollect the box children for this element, because some of the them will be
        /// rebuilt.
        const RECOLLECT_BOX_TREE_CHILDREN = 0b0111_1111_1111 << 4;
        /// Clear the cached inline content sizes and recompute them during the next layout.
        const RECOMPUTE_INLINE_CONTENT_SIZES = 0b1000_0000_0000 << 4;
        /// Rebuild the entire box for this element, which means that every part of layout
        /// needs to happen again.
        const REBUILD_BOX = 0b1111_1111_1111 << 4;
    }
}

impl LayoutDamage {
    pub fn recollect_box_tree_children() -> RestyleDamage {
        RestyleDamage::from_bits_retain(LayoutDamage::RECOLLECT_BOX_TREE_CHILDREN.bits())
    }

    pub fn recompute_inline_content_sizes() -> RestyleDamage {
        RestyleDamage::from_bits_retain(LayoutDamage::RECOMPUTE_INLINE_CONTENT_SIZES.bits())
    }

    pub fn rebuild_box_tree() -> RestyleDamage {
        RestyleDamage::from_bits_retain(LayoutDamage::REBUILD_BOX.bits())
    }

    pub fn has_box_damage(&self) -> bool {
        self.intersects(Self::REBUILD_BOX)
    }
}