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

Code before:

    pub(crate) fn generate_frame_for_script(&mut self) {
        self.frame_delayer.set_pending_frame(true);

        if !self.frame_delayer.needs_new_frame() {
            return;
        }

        let mut transaction = Transaction::new();
        self.generate_frame(&mut transaction, RenderReasons::SCENE);
        self.send_transaction(transaction);

        let waiting_pipelines = self.frame_delayer.take_waiting_pipelines();

        self.send_to_constellation(
            EmbedderToConstellationMessage::NoLongerWaitingOnAsynchronousImageUpdates(
                waiting_pipelines,
            ),
        );

        self.frame_delayer.set_pending_frame(false);
        self.screenshot_taker
            .prepare_screenshot_requests_for_render(self)
    }

    fn maybe_add_to_cache(
        &mut self,
        key: ImageKey,
        data: SerializableImageData,
        animated: bool,
    ) -> ImageData {
        match data {
            SerializableImageData::Raw(shared_memory) => {
                let data = Arc::new(shared_memory.to_vec());
                if animated {
                    self.animation_image_cache.insert(key, Arc::clone(&data));
                }
                ImageData::Raw(data)
            },
            SerializableImageData::External(image) => ImageData::External(image),
        }
    }

    pub(crate) fn update_images(&mut self, updates: SmallVec<[ImageUpdate; 1]>) {
        let mut txn = Transaction::new();
        for update in updates {
            match update {
                ImageUpdate::AddImage(key, desc, data, animated) => {
                    let data = self.maybe_add_to_cache(key, data, animated);
                    txn.add_image(key, desc, data, None);
                },

Review comment (suggestion):
This is now also doing the conversion, so let's adjust the name slightly:


```suggestion
    fn serializable_image_data_to_image_data_maybe_caching(
```

Code after:

    pub(crate) fn generate_frame_for_script(&mut self) {
        self.frame_delayer.set_pending_frame(true);

        if !self.frame_delayer.needs_new_frame() {
            return;
        }

        let mut transaction = Transaction::new();
        self.generate_frame(&mut transaction, RenderReasons::SCENE);
        self.send_transaction(transaction);

        let waiting_pipelines = self.frame_delayer.take_waiting_pipelines();

        self.send_to_constellation(
            EmbedderToConstellationMessage::NoLongerWaitingOnAsynchronousImageUpdates(
                waiting_pipelines,
            ),
        );

        self.frame_delayer.set_pending_frame(false);
        self.screenshot_taker
            .prepare_screenshot_requests_for_render(self)
    }

    fn serializable_image_data_to_image_data_maybe_caching(
        &mut self,
        key: ImageKey,
        data: SerializableImageData,
        is_animated_image: bool,
    ) -> ImageData {
        match data {
            SerializableImageData::Raw(shared_memory) => {
                let data = Arc::new(shared_memory.to_vec());
                if is_animated_image {
                    self.animation_image_cache.insert(key, Arc::clone(&data));
                }
                ImageData::Raw(data)
            },
            SerializableImageData::External(image) => ImageData::External(image),
        }
    }

    pub(crate) fn update_images(&mut self, updates: SmallVec<[ImageUpdate; 1]>) {
        let mut txn = Transaction::new();
        for update in updates {
            match update {
                ImageUpdate::AddImage(key, description, data, is_animated_image) => {
                    txn.add_image(
                        key,
                        description,