mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Some refactoring of ImageCache
This commit is contained in:
parent
872a82b9f0
commit
d723e0cf7b
1 changed files with 60 additions and 57 deletions
|
@ -55,10 +55,17 @@ impl ImageCache {
|
|||
|
||||
loop {
|
||||
match self.from_client.recv() {
|
||||
Prefetch(url) => {
|
||||
Prefetch(url) => self.prefetch(url),
|
||||
GetImage(url, response) => self.get_image(url, response),
|
||||
Exit => break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*priv*/ fn prefetch(url: url) {
|
||||
if self.prefetch_map.contains_key(url) {
|
||||
// We're already waiting for this image
|
||||
again
|
||||
return
|
||||
}
|
||||
let response_port = port();
|
||||
self.resource_task.send(resource_task::Load(url, response_port.chan()));
|
||||
|
@ -70,7 +77,8 @@ impl ImageCache {
|
|||
|
||||
self.prefetch_map.insert(url, prefetch_data);
|
||||
}
|
||||
GetImage(url, response) => {
|
||||
|
||||
/*priv*/ fn get_image(url: url, response: chan<ImageResponseMsg>) {
|
||||
match self.prefetch_map.find(url) {
|
||||
some(prefetch_data) => {
|
||||
|
||||
|
@ -112,11 +120,6 @@ impl ImageCache {
|
|||
}
|
||||
}
|
||||
}
|
||||
Exit => break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue