mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +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 {
|
loop {
|
||||||
match self.from_client.recv() {
|
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) {
|
if self.prefetch_map.contains_key(url) {
|
||||||
// We're already waiting for this image
|
// We're already waiting for this image
|
||||||
again
|
return
|
||||||
}
|
}
|
||||||
let response_port = port();
|
let response_port = port();
|
||||||
self.resource_task.send(resource_task::Load(url, response_port.chan()));
|
self.resource_task.send(resource_task::Load(url, response_port.chan()));
|
||||||
|
@ -70,7 +77,8 @@ impl ImageCache {
|
||||||
|
|
||||||
self.prefetch_map.insert(url, prefetch_data);
|
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) {
|
match self.prefetch_map.find(url) {
|
||||||
some(prefetch_data) => {
|
some(prefetch_data) => {
|
||||||
|
|
||||||
|
@ -112,11 +120,6 @@ impl ImageCache {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Exit => break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue