Repository: servo/servo
File: components/compositing/largest_contentful_paint_calculator.rs (Rust)

Code before:
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use base::cross_process_instant::CrossProcessInstant;
use base::id::WebViewId;
use compositing_traits::largest_contentful_paint_candidate::{
    LCPCandidate, LargestContentfulPaint,
};
use rustc_hash::{FxHashMap, FxHashSet};
use webrender_api::PipelineId;

/// Holds the [`LargestContentfulPaintsContainer`] for each pipeline.
#[derive(Default)]
pub(crate) struct LargestContentfulPaintCalculator {
    lcp_containers: FxHashMap<PipelineId, LargestContentfulPaintsContainer>,
    disabled_lcp_for_webviews: FxHashSet<WebViewId>,
}

impl LargestContentfulPaintCalculator {
    pub(crate) fn new() -> Self {
        Self {
            lcp_containers: Default::default(),
            disabled_lcp_for_webviews: Default::default(),
        }
    }

    pub fn append_lcp_candidate(
        &mut self,
        webview_id: WebViewId,
        pipeline_id: PipelineId,
        candidate: LCPCandidate,
    ) -> bool {
        if self.disabled_lcp_for_webviews.contains(&webview_id) {
            return false;
        }
        self.lcp_containers
            .entry(pipeline_id)
            .or_default()
            .lcp_candidates
            .push(candidate);
        true
    }

    pub fn remove_lcp_candidates_for_pipeline(&mut self, pipeline_id: PipelineId) {
        self.lcp_containers.remove(&pipeline_id);
    }

    pub fn calculate_largest_contentful_paint(
        &mut self,
        paint_time: CrossProcessInstant,
        pipeline_id: PipelineId,
    ) -> Option<LargestContentfulPaint> {

Review comment (suggestion):
```suggestion
    pub(crate) fn append_lcp_candidate(
```

Code after:
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use base::cross_process_instant::CrossProcessInstant;
use base::id::WebViewId;
use compositing_traits::largest_contentful_paint_candidate::{
    LCPCandidate, LargestContentfulPaint,
};
use rustc_hash::{FxHashMap, FxHashSet};
use webrender_api::PipelineId;

/// Holds the [`LargestContentfulPaintsContainer`] for each pipeline.
#[derive(Default)]
pub(crate) struct LargestContentfulPaintCalculator {
    lcp_containers: FxHashMap<PipelineId, LargestContentfulPaintsContainer>,
    disabled_lcp_for_webviews: FxHashSet<WebViewId>,
}

impl LargestContentfulPaintCalculator {
    pub(crate) fn new() -> Self {
        Self {
            lcp_containers: Default::default(),
            disabled_lcp_for_webviews: Default::default(),
        }
    }

    pub(crate) fn append_lcp_candidate(
        &mut self,
        webview_id: WebViewId,
        pipeline_id: PipelineId,
        candidate: LCPCandidate,
    ) -> bool {
        if self.disabled_lcp_for_webviews.contains(&webview_id) {
            return false;
        }
        self.lcp_containers
            .entry(pipeline_id)
            .or_default()
            .lcp_candidates
            .push(candidate);
        true
    }

    pub(crate) fn remove_lcp_candidates_for_pipeline(&mut self, pipeline_id: PipelineId) {
        self.lcp_containers.remove(&pipeline_id);
    }

    pub(crate) fn calculate_largest_contentful_paint(
        &mut self,
        paint_time: CrossProcessInstant,
        pipeline_id: PipelineId,
    ) -> Option<LargestContentfulPaint> {