aircrafs, locations: optimize with BufReader
This commit is contained in:
parent
2bc0bdace0
commit
22132c0038
|
@ -1,4 +1,5 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::io::BufReader;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
@ -17,7 +18,7 @@ pub struct Aircrafts {
|
||||||
|
|
||||||
impl Aircrafts {
|
impl Aircrafts {
|
||||||
pub fn load(file: &str) -> Self {
|
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();
|
let mut data = HashMap::new();
|
||||||
for result in rdr.deserialize() {
|
for result in rdr.deserialize() {
|
||||||
let aircraft: Aircraft = result.unwrap();
|
let aircraft: Aircraft = result.unwrap();
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::io::BufReader;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ pub struct Locations {
|
||||||
impl Locations {
|
impl Locations {
|
||||||
pub fn load(file: &str) -> Self {
|
pub fn load(file: &str) -> Self {
|
||||||
println!("Loading {}...", file);
|
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();
|
.unwrap();
|
||||||
println!("parsed JSON");
|
println!("parsed JSON");
|
||||||
let obj = json.as_object().expect("json obj");
|
let obj = json.as_object().expect("json obj");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user