Repository: servo/servo
File: components/net/resource_thread.rs (Rust)

Code before:
                cookie_jar.remove_expired_cookies_for_url(&url);
                let cookies = cookie_jar
                    .cookies_data_for_url(&url, source)
                    .map(Serde)
                    .collect();
                consumer.send(cookies).unwrap();
            },
            CoreResourceMsg::GetHistoryState(history_state_id, consumer) => {
                let history_states = http_state.history_states.read();
                consumer
                    .send(history_states.get(&history_state_id).cloned())
                    .unwrap();
            },
            CoreResourceMsg::SetHistoryState(history_state_id, structured_data) => {
                let mut history_states = http_state.history_states.write();
                history_states.insert(history_state_id, structured_data);
            },
            CoreResourceMsg::RemoveHistoryStates(states_to_remove) => {
                let mut history_states = http_state.history_states.write();
                for history_state in states_to_remove {
                    history_states.remove(&history_state);
                }
            },
            CoreResourceMsg::ListCacheOrigins(sender) => {
                let origin_descriptors = http_state.http_cache.origin_descriptors();
                let _ = sender.send(origin_descriptors);
            },
            CoreResourceMsg::ClearCache(sender) => {
                http_state.http_cache.clear();
                if let Some(sender) = sender {
                    let _ = sender.send(());
                }
            },
            CoreResourceMsg::ToFileManager(msg) => self.resource_manager.filemanager.handle(msg),
            CoreResourceMsg::Exit(sender) => {
                if let Some(ref config_dir) = self.config_dir {
                    let auth_cache = http_state.auth_cache.read();
                    base::write_json_to_file(&*auth_cache, config_dir, "auth_cache.json");
                    let jar = http_state.cookie_jar.read();
                    base::write_json_to_file(&*jar, config_dir, "cookie_jar.json");
                    let hsts = http_state.hsts_list.read();
                    base::write_json_to_file(&*hsts, config_dir, "hsts_list.json");
                }
                self.resource_manager.exit();
                let _ = sender.send(());
                return false;
            },
        }
        true
    }
}

Review comment (performance):
```suggestion
                let _ = sender.send(http_state.http_cache.origin_descriptors());
```

Code after:
                cookie_jar.remove_expired_cookies_for_url(&url);
                let cookies = cookie_jar
                    .cookies_data_for_url(&url, source)
                    .map(Serde)
                    .collect();
                consumer.send(cookies).unwrap();
            },
            CoreResourceMsg::ListCookies(sender) => {
                let mut cookie_jar = http_state.cookie_jar.write();
                cookie_jar.remove_all_expired_cookies();
                let _ = sender.send(cookie_jar.cookie_site_descriptors());
            },
            CoreResourceMsg::GetHistoryState(history_state_id, consumer) => {
                let history_states = http_state.history_states.read();
                consumer
                    .send(history_states.get(&history_state_id).cloned())
                    .unwrap();
            },
            CoreResourceMsg::SetHistoryState(history_state_id, structured_data) => {
                let mut history_states = http_state.history_states.write();
                history_states.insert(history_state_id, structured_data);
            },
            CoreResourceMsg::RemoveHistoryStates(states_to_remove) => {
                let mut history_states = http_state.history_states.write();
                for history_state in states_to_remove {
                    history_states.remove(&history_state);
                }
            },
            CoreResourceMsg::GetCacheEntries(sender) => {
                let _ = sender.send(http_state.http_cache.cache_entry_descriptors());
            },
            CoreResourceMsg::ClearCache(sender) => {
                http_state.http_cache.clear();
                if let Some(sender) = sender {
                    let _ = sender.send(());
                }
            },
            CoreResourceMsg::ToFileManager(msg) => self.resource_manager.filemanager.handle(msg),
            CoreResourceMsg::Exit(sender) => {
                if let Some(ref config_dir) = self.config_dir {
                    let auth_cache = http_state.auth_cache.read();
                    base::write_json_to_file(&*auth_cache, config_dir, "auth_cache.json");
                    let jar = http_state.cookie_jar.read();
                    base::write_json_to_file(&*jar, config_dir, "cookie_jar.json");
                    let hsts = http_state.hsts_list.read();
                    base::write_json_to_file(&*hsts, config_dir, "hsts_list.json");
                }
                self.resource_manager.exit();
                let _ = sender.send(());
                return false;
            },