Skip to content

Commit d0e60b7

Browse files
committed
De-~[] Reader and Writer
There's a little more allocation here and there now since from_utf8_owned can't be used with Vec.
1 parent 94a055c commit d0e60b7

File tree

27 files changed

+117
-108
lines changed

27 files changed

+117
-108
lines changed

src/compiletest/procsrv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ pub fn run(lib_path: &str,
8484

8585
Some(Result {
8686
status: status,
87-
out: str::from_utf8_owned(output).unwrap(),
88-
err: str::from_utf8_owned(error).unwrap()
87+
out: str::from_utf8(output.as_slice()).unwrap().to_owned(),
88+
err: str::from_utf8(error.as_slice()).unwrap().to_owned()
8989
})
9090
},
9191
Err(..) => None

src/compiletest/runtest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
153153
match props.pp_exact { Some(_) => 1, None => 2 };
154154

155155
let src = File::open(testfile).read_to_end().unwrap();
156-
let src = str::from_utf8_owned(src).unwrap();
156+
let src = str::from_utf8(src.as_slice()).unwrap().to_owned();
157157
let mut srcs = vec!(src);
158158

159159
let mut round = 0;
@@ -177,7 +177,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
177177
Some(ref file) => {
178178
let filepath = testfile.dir_path().join(file);
179179
let s = File::open(&filepath).read_to_end().unwrap();
180-
str::from_utf8_owned(s).unwrap()
180+
str::from_utf8(s.as_slice()).unwrap().to_owned()
181181
}
182182
None => { (*srcs.get(srcs.len() - 2u)).clone() }
183183
};
@@ -1163,7 +1163,7 @@ fn disassemble_extract(config: &config, _props: &TestProps,
11631163
11641164
fn count_extracted_lines(p: &Path) -> uint {
11651165
let x = File::open(&p.with_extension("ll")).read_to_end().unwrap();
1166-
let x = str::from_utf8_owned(x).unwrap();
1166+
let x = str::from_utf8(x.as_slice()).unwrap();
11671167
x.lines().len()
11681168
}
11691169

src/librustc/back/archive.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ fn run_ar(sess: &Session, args: &str, cwd: Option<&Path>,
5959
if !o.status.success() {
6060
sess.err(format!("{} {} failed with: {}", ar, args.connect(" "),
6161
o.status));
62-
sess.note(format!("stdout ---\n{}", str::from_utf8(o.output).unwrap()));
63-
sess.note(format!("stderr ---\n{}", str::from_utf8(o.error).unwrap()));
62+
sess.note(format!("stdout ---\n{}",
63+
str::from_utf8(o.output.as_slice()).unwrap()));
64+
sess.note(format!("stderr ---\n{}",
65+
str::from_utf8(o.error.as_slice()).unwrap()));
6466
sess.abort_if_errors();
6567
}
6668
o
@@ -129,7 +131,7 @@ impl<'a> Archive<'a> {
129131
/// Lists all files in an archive
130132
pub fn files(&self) -> Vec<~str> {
131133
let output = run_ar(self.sess, "t", None, [&self.dst]);
132-
let output = str::from_utf8(output.output).unwrap();
134+
let output = str::from_utf8(output.output.as_slice()).unwrap();
133135
// use lines_any because windows delimits output with `\r\n` instead of
134136
// just `\n`
135137
output.lines_any().map(|s| s.to_owned()).collect()

src/librustc/back/link.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,9 @@ pub mod write {
337337
if !prog.status.success() {
338338
sess.err(format!("linking with `{}` failed: {}", cc, prog.status));
339339
sess.note(format!("{} arguments: '{}'", cc, args.connect("' '")));
340-
sess.note(str::from_utf8_owned(prog.error + prog.output).unwrap());
340+
let mut note = prog.error.clone();
341+
note.push_all(prog.output.as_slice());
342+
sess.note(str::from_utf8(note.as_slice()).unwrap().to_owned());
341343
sess.abort_if_errors();
342344
}
343345
},
@@ -929,7 +931,8 @@ fn link_rlib<'a>(sess: &'a Session,
929931
let bc = obj_filename.with_extension("bc");
930932
let bc_deflated = obj_filename.with_extension("bc.deflate");
931933
match fs::File::open(&bc).read_to_end().and_then(|data| {
932-
fs::File::create(&bc_deflated).write(flate::deflate_bytes(data).as_slice())
934+
fs::File::create(&bc_deflated)
935+
.write(flate::deflate_bytes(data.as_slice()).as_slice())
933936
}) {
934937
Ok(()) => {}
935938
Err(e) => {
@@ -1025,7 +1028,9 @@ fn link_natively(sess: &Session, dylib: bool, obj_filename: &Path,
10251028
if !prog.status.success() {
10261029
sess.err(format!("linking with `{}` failed: {}", cc_prog, prog.status));
10271030
sess.note(format!("{} arguments: '{}'", cc_prog, cc_args.connect("' '")));
1028-
sess.note(str::from_utf8_owned(prog.error + prog.output).unwrap());
1031+
let mut output = prog.error.clone();
1032+
output.push_all(prog.output.as_slice());
1033+
sess.note(str::from_utf8(output.as_slice()).unwrap().to_owned());
10291034
sess.abort_if_errors();
10301035
}
10311036
},

src/librustc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ pub fn run_compiler(args: &[~str]) {
272272
let ifile = matches.free.get(0).as_slice();
273273
if ifile == "-" {
274274
let contents = io::stdin().read_to_end().unwrap();
275-
let src = str::from_utf8_owned(contents).unwrap();
275+
let src = str::from_utf8(contents.as_slice()).unwrap().to_owned();
276276
(d::StrInput(src), None)
277277
} else {
278278
(d::FileInput(Path::new(ifile)), Some(Path::new(ifile)))

src/librustdoc/html/render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ impl<'a> SourceCollector<'a> {
487487
filename.ends_with("macros>") => return Ok(()),
488488
Err(e) => return Err(e)
489489
};
490-
let contents = str::from_utf8_owned(contents).unwrap();
490+
let contents = str::from_utf8(contents.as_slice()).unwrap();
491491

492492
// Remove the utf-8 BOM if any
493493
let contents = if contents.starts_with("\ufeff") {

src/librustdoc/markdown.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use test::Collector;
2222
fn load_string(input: &Path) -> io::IoResult<Option<~str>> {
2323
let mut f = try!(io::File::open(input));
2424
let d = try!(f.read_to_end());
25-
Ok(str::from_utf8_owned(d))
25+
Ok(str::from_utf8(d.as_slice()).map(|s| s.to_owned()))
2626
}
2727
macro_rules! load_or_return {
2828
($input: expr, $cant_read: expr, $not_utf8: expr) => {

src/librustdoc/test.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
159159
if should_fail && out.status.success() {
160160
fail!("test executable succeeded when it should have failed");
161161
} else if !should_fail && !out.status.success() {
162-
fail!("test executable failed:\n{}", str::from_utf8(out.error));
162+
fail!("test executable failed:\n{}",
163+
str::from_utf8(out.error.as_slice()));
163164
}
164165
}
165166
}

src/libserialize/json.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,8 +1282,8 @@ pub fn from_reader(rdr: &mut io::Reader) -> DecodeResult<Json> {
12821282
Ok(c) => c,
12831283
Err(e) => return Err(IoError(e))
12841284
};
1285-
let s = match str::from_utf8_owned(contents) {
1286-
Some(s) => s,
1285+
let s = match str::from_utf8(contents.as_slice()) {
1286+
Some(s) => s.to_owned(),
12871287
None => return Err(ParseError(~"contents not utf-8", 0, 0))
12881288
};
12891289
let mut parser = Parser::new(s.chars());

src/libstd/io/buffered.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,10 +504,10 @@ mod test {
504504
fn test_read_until() {
505505
let inner = MemReader::new(~[0, 1, 2, 1, 0]);
506506
let mut reader = BufferedReader::with_capacity(2, inner);
507-
assert_eq!(reader.read_until(0), Ok(~[0]));
508-
assert_eq!(reader.read_until(2), Ok(~[1, 2]));
509-
assert_eq!(reader.read_until(1), Ok(~[1]));
510-
assert_eq!(reader.read_until(8), Ok(~[0]));
507+
assert_eq!(reader.read_until(0), Ok(vec!(0)));
508+
assert_eq!(reader.read_until(2), Ok(vec!(1, 2)));
509+
assert_eq!(reader.read_until(1), Ok(vec!(1)));
510+
assert_eq!(reader.read_until(8), Ok(vec!(0)));
511511
assert!(reader.read_until(9).is_err());
512512
}
513513

0 commit comments

Comments
 (0)