Skip to content

Commit

Permalink
chore: fix spaces to tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
yannleretaille committed Oct 15, 2020
1 parent d27887b commit 6ef21c0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 49 deletions.
24 changes: 12 additions & 12 deletions benches/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ use bincode::Options;
const DATABASE_BINFILE: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/database.bin"));

fn bincode_deserialize_database(db_raw: &[u8]) -> Vec<loader::Metadata> {
bincode::options()
bincode::options()
.with_varint_encoding().deserialize(db_raw).unwrap()
}

fn parse_database(db_decoded: Vec<loader::Metadata>) -> Database {
Database::from(db_decoded, false).unwrap()
Database::from(db_decoded, false).unwrap()
}

fn first_query(db: &Database) -> PhoneNumber {
parser::parse_with(db, None, "+16137827274").unwrap()
parser::parse_with(db, None, "+16137827274").unwrap()
}


fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("init");
group.sampling_mode(SamplingMode::Auto);
group.sample_size(50);
let mut group = c.benchmark_group("init");
group.sampling_mode(SamplingMode::Auto);
group.sample_size(50);

group.bench_function("deserialize binencoded database", |b| b.iter(|| bincode_deserialize_database(black_box(DATABASE_BINFILE))));
group.bench_function("deserialize binencoded database", |b| b.iter(|| bincode_deserialize_database(black_box(DATABASE_BINFILE))));

let db_decoded = bincode_deserialize_database(DATABASE_BINFILE);
group.bench_function("parse database (unchecked)", |b| b.iter(|| parse_database(black_box(db_decoded.to_vec()))));
let db_decoded = bincode_deserialize_database(DATABASE_BINFILE);
group.bench_function("parse database (unchecked)", |b| b.iter(|| parse_database(black_box(db_decoded.to_vec()))));

let db = parse_database(db_decoded.to_vec());
group.bench_function("first query", |b| { db.cache().lock().unwrap().clear(); b.iter(|| first_query(black_box(&db))) });
group.finish();
let db = parse_database(db_decoded.to_vec());
group.bench_function("first query", |b| { db.cache().lock().unwrap().clear(); b.iter(|| first_query(black_box(&db))) });
group.finish();
}

criterion_group!(benches, criterion_benchmark);
Expand Down
74 changes: 37 additions & 37 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ pub enum Metadata {
MismatchedTag(String),

/// A required value was missing.
#[error("{phase}: missing value: {name:?}")]
#[allow(unused)] // This is unused in the build script
#[error("{phase}: missing value: {name:?}")]
#[allow(unused)] // This is unused in the build script
MissingValue {
phase: String,
name: String,
Expand Down Expand Up @@ -61,74 +61,74 @@ pub enum Metadata {
pub enum Parse {
/// This generally indicates the string passed in had less than 3 digits in
/// it.
#[error("not a number")]
#[allow(unused)] // This is unused in the build script
#[error("not a number")]
#[allow(unused)] // This is unused in the build script
NoNumber,

/// The country code supplied did not belong to a supported country or
/// non-geographical entity.
#[error("invalid country code")]
#[allow(unused)] // This is unused in the build script
#[error("invalid country code")]
#[allow(unused)] // This is unused in the build script
InvalidCountryCode,

/// This indicates the string started with an international dialing prefix,
/// but after this was stripped from the number, had less digits than any
/// valid phone number (including country code) could have.
#[error("the number is too short after IDD")]
#[allow(unused)] // This is unused in the build script
#[error("the number is too short after IDD")]
#[allow(unused)] // This is unused in the build script
TooShortAfterIdd,

/// This indicates the string, after any country code has been stripped, had
/// less digits than any valid phone number could have.
#[error("the number is too short after the country code")]
#[allow(unused)] // This is unused in the build script
#[error("the number is too short after the country code")]
#[allow(unused)] // This is unused in the build script
TooShortNsn,

/// This indicates the string had more digits than any valid phone number
/// could have.
#[error("the number is too long")]
#[allow(unused)] // This is unused in the build script
TooLong,
#[error("the number is too long")]
#[allow(unused)] // This is unused in the build script
TooLong,

/// A integer parts of a number is malformed, normally this should be caught by the parsing regexes.
#[error("malformed integer part in phone number: {0}")]
MalformedInteger(#[from] std::num::ParseIntError),
/// A integer parts of a number is malformed, normally this should be caught by the parsing regexes.
#[error("malformed integer part in phone number: {0}")]
MalformedInteger(#[from] std::num::ParseIntError),
}


/// Loading of Database) Error
#[derive(Error, Debug)]
pub enum LoadMetadata {

/// Parsing XML failed, the XML is malformed.
#[error("Malformed Metadata XML: {0}")]
Xml(#[from] xml::Error),
/// Parsing XML failed, the XML is malformed.
#[error("Malformed Metadata XML: {0}")]
Xml(#[from] xml::Error),

/// Parsing UTF-8 string from XML failed.
#[error("Non UTF-8 string in Metadata XML: {0}")]
Utf8(#[from] std::str::Utf8Error),
/// Parsing UTF-8 string from XML failed.
#[error("Non UTF-8 string in Metadata XML: {0}")]
Utf8(#[from] std::str::Utf8Error),

/// Metadata Error
#[error("{0}")]
Metadata(#[from] Metadata),
/// Metadata Error
#[error("{0}")]
Metadata(#[from] Metadata),

/// Malformed integer in Metadata XML database
#[error("Malformed integer in Metadata XML: {0}")]
Integer(#[from] std::num::ParseIntError),
/// Malformed integer in Metadata XML database
#[error("Malformed integer in Metadata XML: {0}")]
Integer(#[from] std::num::ParseIntError),

/// Malformed boolean in Metadata XML database
#[error("Malformed boolean in Metadata XML: {0}")]
Bool(#[from] std::str::ParseBoolError),
/// Malformed boolean in Metadata XML database
#[error("Malformed boolean in Metadata XML: {0}")]
Bool(#[from] std::str::ParseBoolError),

/// I/O-Error while reading Metadata XML database
#[error("I/O-Error in Metadata XML: {0}")]
Io(#[from] std::io::Error),
/// I/O-Error while reading Metadata XML database
#[error("I/O-Error in Metadata XML: {0}")]
Io(#[from] std::io::Error),

/// Malformed Regex in Metadata XML database
#[error("Malformed Regex: {0}")]
/// Malformed Regex in Metadata XML database
#[error("Malformed Regex: {0}")]
Regex(#[from] regex::Error),

#[error("Malformed Regex: {0}")]
RegexSyntax(#[from] regex_syntax::Error),
RegexSyntax(#[from] regex_syntax::Error),

}

0 comments on commit 6ef21c0

Please sign in to comment.