Skip to content

Commit

Permalink
Use a BufReader as underlying reader.
Browse files Browse the repository at this point in the history
This little change massively reduces the amount of syscalls done when reading files. Using the test files from mapeditor#284, I saw a 400% performance boost.
  • Loading branch information
Deukhoofd committed Apr 1, 2024
1 parent 98fbedb commit bb919da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Implement `ResourceReader` for appropiate functions. (#272) **Read the README's FAQ for more information about this change.**
- Support for custom type properties. (#283)

### Changed
- Underlying reader for maps now uses a BufReader, which should give a large performance boost. (#286)

## Fixed
- `ObjectShape::Text::kerning`'s default value, which should have been set to `true` instead of `false`. (#278)

Expand Down
6 changes: 4 additions & 2 deletions src/reader.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::io::BufReader;
use std::{fs::File, io::Read, path::Path};

/// A trait defining types that can load data from a [`ResourcePath`](crate::ResourcePath).
Expand Down Expand Up @@ -48,11 +49,12 @@ impl FilesystemResourceReader {
}

impl ResourceReader for FilesystemResourceReader {
type Resource = File;
type Resource = BufReader<File>;
type Error = std::io::Error;

fn read_from(&mut self, path: &Path) -> std::result::Result<Self::Resource, Self::Error> {
File::open(path)
let file = File::open(path)?;
Ok(BufReader::new(file))
}
}

Expand Down

0 comments on commit bb919da

Please sign in to comment.