mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Make ProgressMsg use Vec.
This commit is contained in:
parent
cc7d04702d
commit
6e617d8eba
9 changed files with 27 additions and 24 deletions
|
@ -53,14 +53,16 @@ fn load(url: Url, start_chan: Sender<LoadResponse>) {
|
||||||
progress_chan.send(Done(Err(())));
|
progress_chan.send(Done(Err(())));
|
||||||
}
|
}
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
progress_chan.send(Payload(data));
|
let data: ~[u8] = data;
|
||||||
|
progress_chan.send(Payload(data.move_iter().collect()));
|
||||||
progress_chan.send(Done(Ok(())));
|
progress_chan.send(Done(Ok(())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// FIXME: Since the %-decoded URL is already a str, we can't
|
// FIXME: Since the %-decoded URL is already a str, we can't
|
||||||
// handle UTF8-incompatible encodings.
|
// handle UTF8-incompatible encodings.
|
||||||
progress_chan.send(Payload(parts[1].as_bytes().into_owned()));
|
let bytes: &[u8] = parts[1].as_bytes();
|
||||||
|
progress_chan.send(Payload(bytes.iter().map(|&x| x).collect()));
|
||||||
progress_chan.send(Done(Ok(())));
|
progress_chan.send(Done(Ok(())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +71,7 @@ fn load(url: Url, start_chan: Sender<LoadResponse>) {
|
||||||
fn assert_parse(url: &'static str,
|
fn assert_parse(url: &'static str,
|
||||||
content_type: Option<(~str, ~str)>,
|
content_type: Option<(~str, ~str)>,
|
||||||
charset: Option<~str>,
|
charset: Option<~str>,
|
||||||
data: Option<~[u8]>) {
|
data: Option<Vec<u8>>) {
|
||||||
use std::from_str::FromStr;
|
use std::from_str::FromStr;
|
||||||
use std::comm;
|
use std::comm;
|
||||||
|
|
||||||
|
@ -100,35 +102,35 @@ fn empty_invalid() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn plain() {
|
fn plain() {
|
||||||
assert_parse("data:,hello%20world", None, None, Some(bytes!("hello world").into_owned()));
|
assert_parse("data:,hello%20world", None, None, Some(bytes!("hello world").iter().map(|&x| x).collect()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn plain_ct() {
|
fn plain_ct() {
|
||||||
assert_parse("data:text/plain,hello",
|
assert_parse("data:text/plain,hello",
|
||||||
Some((~"text", ~"plain")), None, Some(bytes!("hello").into_owned()));
|
Some((~"text", ~"plain")), None, Some(bytes!("hello").iter().map(|&x| x).collect()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn plain_charset() {
|
fn plain_charset() {
|
||||||
assert_parse("data:text/plain;charset=latin1,hello",
|
assert_parse("data:text/plain;charset=latin1,hello",
|
||||||
Some((~"text", ~"plain")), Some(~"latin1"), Some(bytes!("hello").into_owned()));
|
Some((~"text", ~"plain")), Some(~"latin1"), Some(bytes!("hello").iter().map(|&x| x).collect()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn base64() {
|
fn base64() {
|
||||||
assert_parse("data:;base64,C62+7w==", None, None, Some(~[0x0B, 0xAD, 0xBE, 0xEF]));
|
assert_parse("data:;base64,C62+7w==", None, None, Some(vec!(0x0B, 0xAD, 0xBE, 0xEF)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn base64_ct() {
|
fn base64_ct() {
|
||||||
assert_parse("data:application/octet-stream;base64,C62+7w==",
|
assert_parse("data:application/octet-stream;base64,C62+7w==",
|
||||||
Some((~"application", ~"octet-stream")), None, Some(~[0x0B, 0xAD, 0xBE, 0xEF]));
|
Some((~"application", ~"octet-stream")), None, Some(vec!(0x0B, 0xAD, 0xBE, 0xEF)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn base64_charset() {
|
fn base64_charset() {
|
||||||
assert_parse("data:text/plain;charset=koi8-r;base64,8PLl9+XkIO3l5Pfl5A==",
|
assert_parse("data:text/plain;charset=koi8-r;base64,8PLl9+XkIO3l5Pfl5A==",
|
||||||
Some((~"text", ~"plain")), Some(~"koi8-r"),
|
Some((~"text", ~"plain")), Some(~"koi8-r"),
|
||||||
Some(~[0xF0, 0xF2, 0xE5, 0xF7, 0xE5, 0xE4, 0x20, 0xED, 0xE5, 0xE4, 0xF7, 0xE5, 0xE4]));
|
Some(vec!(0xF0, 0xF2, 0xE5, 0xF7, 0xE5, 0xE4, 0x20, 0xED, 0xE5, 0xE4, 0xF7, 0xE5, 0xE4)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ fn read_all(reader: &mut io::Stream, progress_chan: &Sender<ProgressMsg>)
|
||||||
loop {
|
loop {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
match reader.push_exact(&mut buf, READ_SIZE) {
|
match reader.push_exact(&mut buf, READ_SIZE) {
|
||||||
Ok(_) => progress_chan.send(Payload(buf.iter().map(|&x| x).collect())),
|
Ok(_) => progress_chan.send(Payload(buf)),
|
||||||
Err(e) => match e.kind {
|
Err(e) => match e.kind {
|
||||||
io::EndOfFile => return Ok(()),
|
io::EndOfFile => return Ok(()),
|
||||||
_ => return Err(()),
|
_ => return Err(()),
|
||||||
|
|
|
@ -104,7 +104,8 @@ fn load(mut url: Url, start_chan: Sender<LoadResponse>) {
|
||||||
match response.read(buf) {
|
match response.read(buf) {
|
||||||
Ok(len) => {
|
Ok(len) => {
|
||||||
unsafe { buf.set_len(len); }
|
unsafe { buf.set_len(len); }
|
||||||
progress_chan.send(Payload(buf));
|
let buf: ~[u8] = buf;
|
||||||
|
progress_chan.send(Payload(buf.move_iter().collect()));
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
progress_chan.send(Done(Ok(())));
|
progress_chan.send(Done(Ok(())));
|
||||||
|
|
|
@ -21,8 +21,8 @@ pub fn Image(width: u32, height: u32, color_type: png::ColorType, data: ~[u8]) -
|
||||||
|
|
||||||
static TEST_IMAGE: &'static [u8] = include_bin!("test.jpeg");
|
static TEST_IMAGE: &'static [u8] = include_bin!("test.jpeg");
|
||||||
|
|
||||||
pub fn test_image_bin() -> ~[u8] {
|
pub fn test_image_bin() -> Vec<u8> {
|
||||||
TEST_IMAGE.into_owned()
|
TEST_IMAGE.iter().map(|&x| x).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(pcwalton): Speed up with SIMD, or better yet, find some way to not do this.
|
// TODO(pcwalton): Speed up with SIMD, or better yet, find some way to not do this.
|
||||||
|
|
|
@ -491,7 +491,7 @@ fn load_image_data(url: Url, resource_task: ResourceTask) -> Result<~[u8], ()> {
|
||||||
loop {
|
loop {
|
||||||
match progress_port.recv() {
|
match progress_port.recv() {
|
||||||
resource_task::Payload(data) => {
|
resource_task::Payload(data) => {
|
||||||
image_data.push_all(data);
|
image_data.push_all(data.as_slice());
|
||||||
}
|
}
|
||||||
resource_task::Done(result::Ok(..)) => {
|
resource_task::Done(result::Ok(..)) => {
|
||||||
return Ok(image_data);
|
return Ok(image_data);
|
||||||
|
@ -554,7 +554,7 @@ mod tests {
|
||||||
struct SendBogusImage;
|
struct SendBogusImage;
|
||||||
impl Closure for SendBogusImage {
|
impl Closure for SendBogusImage {
|
||||||
fn invoke(&self, response: Sender<resource_task::ProgressMsg>) {
|
fn invoke(&self, response: Sender<resource_task::ProgressMsg>) {
|
||||||
response.send(resource_task::Payload(~[]));
|
response.send(resource_task::Payload(vec!()));
|
||||||
response.send(resource_task::Done(Ok(())));
|
response.send(resource_task::Done(Ok(())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ pub struct LoadResponse {
|
||||||
#[deriving(Eq,Show)]
|
#[deriving(Eq,Show)]
|
||||||
pub enum ProgressMsg {
|
pub enum ProgressMsg {
|
||||||
/// Binary data - there may be multiple of these
|
/// Binary data - there may be multiple of these
|
||||||
Payload(~[u8]),
|
Payload(Vec<u8>),
|
||||||
/// Indicates loading is complete, either successfully or not
|
/// Indicates loading is complete, either successfully or not
|
||||||
Done(Result<(), ()>)
|
Done(Result<(), ()>)
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ pub fn load_whole_resource(resource_task: &ResourceTask, url: Url)
|
||||||
let mut buf = ~[];
|
let mut buf = ~[];
|
||||||
loop {
|
loop {
|
||||||
match response.progress_port.recv() {
|
match response.progress_port.recv() {
|
||||||
Payload(data) => buf.push_all(data),
|
Payload(data) => buf.push_all(data.as_slice()),
|
||||||
Done(Ok(())) => return Ok((response.metadata, buf)),
|
Done(Ok(())) => return Ok((response.metadata, buf)),
|
||||||
Done(Err(e)) => return Err(e)
|
Done(Err(e)) => return Err(e)
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ static snicklefritz_payload: [u8, ..3] = [1, 2, 3];
|
||||||
fn snicklefritz_loader_factory() -> LoaderTask {
|
fn snicklefritz_loader_factory() -> LoaderTask {
|
||||||
let f: LoaderTask = proc(url: Url, start_chan: Sender<LoadResponse>) {
|
let f: LoaderTask = proc(url: Url, start_chan: Sender<LoadResponse>) {
|
||||||
let progress_chan = start_sending(start_chan, Metadata::default(url));
|
let progress_chan = start_sending(start_chan, Metadata::default(url));
|
||||||
progress_chan.send(Payload(snicklefritz_payload.into_owned()));
|
progress_chan.send(Payload(Vec::from_slice(snicklefritz_payload)));
|
||||||
progress_chan.send(Done(Ok(())));
|
progress_chan.send(Done(Ok(())));
|
||||||
};
|
};
|
||||||
f
|
f
|
||||||
|
@ -244,7 +244,7 @@ fn should_delegate_to_scheme_loader() {
|
||||||
let response = start.recv();
|
let response = start.recv();
|
||||||
let progress = response.progress_port;
|
let progress = response.progress_port;
|
||||||
|
|
||||||
assert!(progress.recv() == Payload(snicklefritz_payload.into_owned()));
|
assert!(progress.recv() == Payload(Vec::from_slice(snicklefritz_payload)));
|
||||||
assert!(progress.recv() == Done(Ok(())));
|
assert!(progress.recv() == Done(Ok(())));
|
||||||
resource_task.send(Exit);
|
resource_task.send(Exit);
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,8 +62,8 @@ struct ProgressMsgPortIterator {
|
||||||
progress_port: Receiver<ProgressMsg>
|
progress_port: Receiver<ProgressMsg>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Iterator<~[u8]> for ProgressMsgPortIterator {
|
impl Iterator<Vec<u8>> for ProgressMsgPortIterator {
|
||||||
fn next(&mut self) -> Option<~[u8]> {
|
fn next(&mut self) -> Option<Vec<u8>> {
|
||||||
match self.progress_port.recv() {
|
match self.progress_port.recv() {
|
||||||
Payload(data) => Some(data),
|
Payload(data) => Some(data),
|
||||||
Done(..) => None
|
Done(..) => None
|
||||||
|
|
|
@ -493,7 +493,7 @@ pub fn parse_html(page: &Page,
|
||||||
match load_response.progress_port.recv() {
|
match load_response.progress_port.recv() {
|
||||||
Payload(data) => {
|
Payload(data) => {
|
||||||
debug!("received data");
|
debug!("received data");
|
||||||
parser.parse_chunk(data);
|
parser.parse_chunk(data.as_slice());
|
||||||
}
|
}
|
||||||
Done(Err(..)) => {
|
Done(Err(..)) => {
|
||||||
fail!("Failed to load page URL {:s}", url.to_str());
|
fail!("Failed to load page URL {:s}", url.to_str());
|
||||||
|
|
|
@ -41,13 +41,13 @@ pub struct StyleRule {
|
||||||
|
|
||||||
|
|
||||||
impl Stylesheet {
|
impl Stylesheet {
|
||||||
pub fn from_bytes_iter<I: Iterator<~[u8]>>(
|
pub fn from_bytes_iter<I: Iterator<Vec<u8>>>(
|
||||||
mut input: I, base_url: Url, protocol_encoding_label: Option<&str>,
|
mut input: I, base_url: Url, protocol_encoding_label: Option<&str>,
|
||||||
environment_encoding: Option<EncodingRef>) -> Stylesheet {
|
environment_encoding: Option<EncodingRef>) -> Stylesheet {
|
||||||
let mut bytes = ~[];
|
let mut bytes = ~[];
|
||||||
// TODO: incremental decoding and tokinization/parsing
|
// TODO: incremental decoding and tokinization/parsing
|
||||||
for chunk in input {
|
for chunk in input {
|
||||||
bytes.push_all(chunk)
|
bytes.push_all(chunk.as_slice())
|
||||||
}
|
}
|
||||||
Stylesheet::from_bytes(bytes, base_url, protocol_encoding_label, environment_encoding)
|
Stylesheet::from_bytes(bytes, base_url, protocol_encoding_label, environment_encoding)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue