Rollup merge of #47328 - mbrubeck:fs_read, r=sfackler

Use the new fs_read_write functions in rustc internals

Uses `fs::read` and `fs::write` (added by #45837) where appropriate, to simplify code and dog-food these new APIs.  This also improves performance, when combined with #47324.
This commit is contained in:
kennytm 2018-01-13 02:26:35 +08:00 committed by GitHub
commit 7ffdabd401
18 changed files with 42 additions and 64 deletions

View file

@ -55,7 +55,7 @@ use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc::ich::{ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED};
use graphviz::IntoCow;
use std::env;
use std::fs::File;
use std::fs::{self, File};
use std::io::Write;
use syntax::ast;
use syntax_pos::Span;
@ -260,7 +260,7 @@ fn dump_graph(tcx: TyCtxt) {
let dot_path = format!("{}.dot", path);
let mut v = Vec::new();
dot::render(&GraphvizDepGraph(nodes, edges), &mut v).unwrap();
File::create(&dot_path).and_then(|mut f| f.write_all(&v)).unwrap();
fs::write(dot_path, v).unwrap();
}
}

View file

@ -16,6 +16,7 @@
#![deny(warnings)]
#![feature(conservative_impl_trait)]
#![feature(fs_read_write)]
#![feature(i128_type)]
#![feature(inclusive_range_syntax)]
#![feature(specialization)]

View file

@ -21,7 +21,7 @@
use std::io::{self, Read};
use std::path::Path;
use std::fs::File;
use std::fs;
use std::env;
use rustc::session::config::nightly_options;
@ -66,11 +66,7 @@ pub fn read_file(report_incremental_info: bool, path: &Path)
return Ok(None);
}
let mut file = File::open(path)?;
let file_size = file.metadata()?.len() as usize;
let mut data = Vec::with_capacity(file_size);
file.read_to_end(&mut data)?;
let data = fs::read(path)?;
let mut file = io::Cursor::new(data);

View file

@ -15,8 +15,8 @@ use rustc::util::common::time;
use rustc_data_structures::fx::FxHashMap;
use rustc_serialize::Encodable as RustcEncodable;
use rustc_serialize::opaque::Encoder;
use std::io::{self, Cursor, Write};
use std::fs::{self, File};
use std::io::{self, Cursor};
use std::fs;
use std::path::PathBuf;
use super::data::*;
@ -125,7 +125,7 @@ fn save_in<F>(sess: &Session, path_buf: PathBuf, encode: F)
// write the data out
let data = wr.into_inner();
match File::create(&path_buf).and_then(|mut file| file.write_all(&data)) {
match fs::write(&path_buf, data) {
Ok(_) => {
debug!("save: data written to disk successfully");
}