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

Code before:
pub(crate) struct LargestContentfulPaintCalculator {
    lcp_containers: FxHashMap<PipelineId, LargestContentfulPaintsContainer>,
    disabled_webviews: FxHashSet<WebViewId>,
}

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

    pub(crate) fn append_lcp_candidate(
        &mut self,
        pipeline_id: PipelineId,
        candidate: LCPCandidate,
    ) {
        self.lcp_containers
            .entry(pipeline_id)
            .or_default()
            .lcp_candidates
            .push(candidate);
    }

    pub(crate) fn enabled_for_webview(&self, webview_id: WebViewId) -> bool {
        !self.disabled_webviews.contains(&webview_id)
    }

    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> {
        self.lcp_containers
            .get_mut(&pipeline_id)
            .and_then(|container| container.calculate_largest_contentful_paint(paint_time))
    }

    pub(crate) fn disable_for_webview(&mut self, webview_id: WebViewId) {
        self.disabled_webviews.insert(webview_id);
    }

    pub(crate) fn enable_for_webview(&mut self, webview_id: WebViewId) {
        self.disabled_webviews.remove(&webview_id);
    }
}

Review comment (suggestion):
Nit: if you don't consume the webview_id, make it a reference. Do this for the other API's as well, such as  `enable_for_webview`. For `disable_for_webview` you can't, since you insert the id.

That way, you don't need to manually refer to it in the `contains` call.

```suggestion
    pub(crate) fn enabled_for_webview(&self, webview_id: &WebViewId) -> bool {
```

Code after:
pub(crate) struct LargestContentfulPaintCalculator {
    lcp_containers: FxHashMap<PipelineId, LargestContentfulPaintsContainer>,
    disabled_webviews: FxHashSet<WebViewId>,
}

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

    pub(crate) fn append_lcp_candidate(
        &mut self,
        candidate: LCPCandidate,
        pipeline_id: PipelineId,
        webview_id: &WebViewId,
    ) {
        assert!(self.enabled_for_webview(webview_id));
        self.lcp_containers
            .entry(pipeline_id)
            .or_default()
            .lcp_candidates
            .push(candidate);
    }

    pub(crate) fn enabled_for_webview(&self, webview_id: &WebViewId) -> bool {
        !self.disabled_webviews.contains(webview_id)
    }

    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> {
        self.lcp_containers
            .get_mut(&pipeline_id)
            .and_then(|container| container.calculate_largest_contentful_paint(paint_time))
    }

    /// <https://www.w3.org/TR/largest-contentful-paint/#limitations>
    pub(crate) fn disable_for_webview(&mut self, webview_id: WebViewId) {
        self.disabled_webviews.insert(webview_id);
    }

    pub(crate) fn enable_for_webview(&mut self, webview_id: &WebViewId) {