Don't store file content string in File
This commit is contained in:
parent
721718eee4
commit
d169037b7a
3 changed files with 16 additions and 11 deletions
15
src/files.rs
15
src/files.rs
|
|
@ -290,16 +290,24 @@ impl Files {
|
||||||
pub fn save(&self) -> Result<()> {
|
pub fn save(&self) -> Result<()> {
|
||||||
for file in &self.files {
|
for file in &self.files {
|
||||||
if file.dirty {
|
if file.dirty {
|
||||||
Self::save_file(file)?;
|
self.save_file(file)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_file(file: &LoadedFile) -> Result<()> {
|
fn save_file(&self, file: &LoadedFile) -> Result<()> {
|
||||||
// TODO Sort commands within file
|
// TODO Sort commands within file
|
||||||
|
|
||||||
|
let previous = self
|
||||||
|
.cs_files
|
||||||
|
.get(file.cs_id)
|
||||||
|
.expect("cs id is valid")
|
||||||
|
.source();
|
||||||
|
|
||||||
let formatted = file.file.format(&file.removed);
|
let formatted = file.file.format(&file.removed);
|
||||||
if file.file.contents == formatted {
|
|
||||||
|
if previous == &formatted {
|
||||||
println!("Unchanged file {:?}", file.name);
|
println!("Unchanged file {:?}", file.name);
|
||||||
} else {
|
} else {
|
||||||
println!("Saving file {:?}", file.name);
|
println!("Saving file {:?}", file.name);
|
||||||
|
|
@ -308,6 +316,7 @@ impl Files {
|
||||||
error: e,
|
error: e,
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -381,7 +381,6 @@ pub enum Command {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct File {
|
pub struct File {
|
||||||
pub contents: String,
|
|
||||||
pub commands: Vec<Spanned<Command>>,
|
pub commands: Vec<Spanned<Command>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -389,9 +388,6 @@ impl File {
|
||||||
/// Create an empty dummy file. This file should only be used as a
|
/// Create an empty dummy file. This file should only be used as a
|
||||||
/// placeholder value.
|
/// placeholder value.
|
||||||
pub fn dummy() -> Self {
|
pub fn dummy() -> Self {
|
||||||
Self {
|
Self { commands: vec![] }
|
||||||
contents: String::new(),
|
|
||||||
commands: vec![],
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -834,7 +834,7 @@ fn parse_command(p: Pair<'_, Rule>) -> Result<Spanned<Command>> {
|
||||||
Ok(Spanned::new(span, command))
|
Ok(Spanned::new(span, command))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_file(p: Pair<'_, Rule>, contents: String) -> Result<File> {
|
pub fn parse_file(p: Pair<'_, Rule>) -> Result<File> {
|
||||||
assert_eq!(p.as_rule(), Rule::file);
|
assert_eq!(p.as_rule(), Rule::file);
|
||||||
|
|
||||||
let mut commands = vec![];
|
let mut commands = vec![];
|
||||||
|
|
@ -847,7 +847,7 @@ pub fn parse_file(p: Pair<'_, Rule>, contents: String) -> Result<File> {
|
||||||
commands.push(parse_command(p)?);
|
commands.push(parse_command(p)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(File { contents, commands })
|
Ok(File { commands })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse(path: &Path, input: &str) -> Result<File> {
|
pub fn parse(path: &Path, input: &str) -> Result<File> {
|
||||||
|
|
@ -857,5 +857,5 @@ pub fn parse(path: &Path, input: &str) -> Result<File> {
|
||||||
let file_pair = pairs.next().unwrap();
|
let file_pair = pairs.next().unwrap();
|
||||||
assert_eq!(pairs.next(), None);
|
assert_eq!(pairs.next(), None);
|
||||||
|
|
||||||
parse_file(file_pair, input.to_string()).map_err(|e| e.with_path(&pathstr))
|
parse_file(file_pair).map_err(|e| e.with_path(&pathstr))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue