~ntietz/isabella-db

aa4d34ac1f5bc2f20b309675d0a4df3caf697bf5 — Nicole Tietz-Sokolskaya 1 year, 3 months ago a0772d9
Read in the entire file, rather than use buffering, to shave off a bit of time (25% savings in read)
1 files changed, 9 insertions(+), 8 deletions(-)

M isabella/src/bin/idb.rs
M isabella/src/bin/idb.rs => isabella/src/bin/idb.rs +9 -8
@@ 1,5 1,5 @@
use std::fs::File;
use std::io::{BufReader, BufWriter};
use std::io::{Read, Write};

use clap::{Parser, Subcommand};
use isabella_db::db::GameDB;


@@ 46,20 46,21 @@ fn main() {
            let file = PgnFile::new(args.filename).expect("should open the file");
            let db = GameDB::from_pgn(file);

            let outfile: File = File::options()
            let buf = bincode::serialize(&db).expect("serializing should work");

            let mut outfile: File = File::options()
                .write(true)
                .create(true)
                .open(outfilename)
                .expect("should open file to write");
            let writer = BufWriter::new(outfile);

            bincode::serialize_into(writer, &db).expect("serializing should work");
            outfile.write_all(&buf).expect("should write to file");
        }
        Commands::Load => {
            let file: File = File::open(args.filename).expect("should open the file");
            let reader = BufReader::new(file);
            let mut file: File = File::open(args.filename).expect("should open the file");
            let mut buf: Vec<u8> = Vec::new();
            file.read_to_end(&mut buf).expect("should read");

            let db: GameDB = bincode::deserialize_from(reader).expect("deserializing should work");
            let db: GameDB = bincode::deserialize(&buf).expect("deserializing should work");
            println!("loaded {} games", db.len());
        }
    };