aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-07-26 00:18:10 -0600
committerbors-servo <metajack+bors@gmail.com>2015-07-26 00:18:10 -0600
commitfd1bf1900d876be2da4743c65ea0956be1057453 (patch)
tree070969ed84014d3eb84ef88ca1b903186ab35b3f /components/script
parent3af6992151b087412b2dd460d20b34fb9fc2f28f (diff)
parent20f78b4fcbec9548a2779e52583db4ce0947b4d7 (diff)
downloadservo-fd1bf1900d876be2da4743c65ea0956be1057453.tar.gz
servo-fd1bf1900d876be2da4743c65ea0956be1057453.zip
Auto merge of #6776 - notriddle:filereader-matches, r=jdm
Remove unnecessarily verbose matches. Fixes #6766. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6776) <!-- Reviewable:end -->
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/filereader.rs37
1 files changed, 17 insertions, 20 deletions
diff --git a/components/script/dom/filereader.rs b/components/script/dom/filereader.rs
index 6825437dda1..964a980a0b1 100644
--- a/components/script/dom/filereader.rs
+++ b/components/script/dom/filereader.rs
@@ -227,33 +227,30 @@ impl FileReader {
fn perform_readastext(blob_body: BlobBody)
-> Result<Option<DOMString>, DOMErrorName> {
+ let blob_label = &blob_body.label;
+ let blob_type = &blob_body.blobtype;
+ let blob_bytes = &blob_body.bytes[..];
+
//https://w3c.github.io/FileAPI/#encoding-determination
// Steps 1 & 2 & 3
- let mut encoding = match blob_body.label {
- Some(e) => encoding_from_whatwg_label(&e),
- None => None
- };
+ let mut encoding = blob_label.as_ref()
+ .map(|string| &**string)
+ .and_then(encoding_from_whatwg_label);
// Step 4 & 5
- encoding = match encoding {
- Some(e) => Some(e),
- None => {
- let resultmime = blob_body.blobtype.parse::<Mime>().ok();
- resultmime.and_then(|Mime(_, _, ref parameters)| {
- parameters.iter()
- .find(|&&(ref k, _)| &Attr::Charset == k)
- .and_then(|&(_, ref v)| encoding_from_whatwg_label(&v.to_string()))
- })
- }
- };
+ encoding = encoding.or_else(|| {
+ let resultmime = blob_type.parse::<Mime>().ok();
+ resultmime.and_then(|Mime(_, _, ref parameters)| {
+ parameters.iter()
+ .find(|&&(ref k, _)| &Attr::Charset == k)
+ .and_then(|&(_, ref v)| encoding_from_whatwg_label(&v.to_string()))
+ })
+ });
// Step 6
- let enc = match encoding {
- Some(code) => code,
- None => UTF_8 as EncodingRef
- };
+ let enc = encoding.unwrap_or(UTF_8 as EncodingRef);
- let convert = &blob_body.bytes[..];
+ let convert = blob_bytes;
// Step 7
let output = enc.decode(convert, DecoderTrap::Replace).unwrap();
Ok(Some(output))