aircrafs, locations: optimize with BufReader

This commit is contained in:
Astro 2021-10-30 00:12:34 +02:00
parent 2bc0bdace0
commit 22132c0038
2 changed files with 4 additions and 2 deletions

View File

@ -1,4 +1,5 @@
use std::collections::HashMap;
use std::io::BufReader;
use std::fs::File;
use serde::Deserialize;
@ -17,7 +18,7 @@ pub struct Aircrafts {
impl Aircrafts {
pub fn load(file: &str) -> Self {
let mut rdr = csv::Reader::from_reader(File::open(file).unwrap());
let mut rdr = csv::Reader::from_reader(BufReader::new(File::open(file).unwrap()));
let mut data = HashMap::new();
for result in rdr.deserialize() {
let aircraft: Aircraft = result.unwrap();

View File

@ -1,4 +1,5 @@
use std::collections::HashMap;
use std::io::BufReader;
use std::fs::File;
use std::sync::Arc;
@ -35,7 +36,7 @@ pub struct Locations {
impl Locations {
pub fn load(file: &str) -> Self {
println!("Loading {}...", file);
let json: serde_json::Value = serde_json::from_reader(File::open(file).unwrap())
let json: serde_json::Value = serde_json::from_reader(BufReader::new(File::open(file).unwrap()))
.unwrap();
println!("parsed JSON");
let obj = json.as_object().expect("json obj");