Use FxHashMap instead of HashMap (#252)

This commit is contained in:
Lawrence Khadka 2019-04-20 05:37:14 -05:00 коммит произвёл Marco
Родитель 863c1b08c1
Коммит 14e4c76fd6
13 изменённых файлов: 297 добавлений и 111 удалений

16
Cargo.lock сгенерированный
Просмотреть файл

@ -36,6 +36,11 @@ name = "build_const"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "byteorder"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cc"
version = "1.0.32"
@ -167,6 +172,7 @@ dependencies = [
"md5 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
@ -452,6 +458,14 @@ dependencies = [
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc-hash"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc_version"
version = "0.2.3"
@ -630,6 +644,7 @@ dependencies = [
"checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799"
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
"checksum build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39"
"checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb"
"checksum cc 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)" = "ad0daef304fa0b4238f5f7ed7178774b43b06f6a9b6509f6642bef4ff1f7b9b2"
"checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4"
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
@ -678,6 +693,7 @@ dependencies = [
"checksum regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53ee8cfdddb2e0291adfb9f13d31d3bbe0a03c9a402c01b1e24188d86c35b24f"
"checksum regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8c2f35eedad5295fdf00a63d7d4b238135723f92b434ec06774dad15c7ab0861"
"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
"checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267"

Просмотреть файл

@ -38,6 +38,7 @@ uuid = { version = "^0.7", features = ["v4"] }
globset = "^0.4"
xml-rs = "^0.8"
smallvec = "^0.6"
rustc-hash = "^1.0"
[dev-dependencies]
regex = "^1.1"

Просмотреть файл

@ -1,14 +1,15 @@
#![feature(test)]
extern crate grcov;
extern crate rustc_hash;
extern crate test;
use grcov::{CovResult, Function};
use std::collections::HashMap;
use rustc_hash::FxHashMap;
use test::{black_box, Bencher};
#[bench]
fn bench_filter_covered(b: &mut Bencher) {
let mut functions: HashMap<String, Function> = HashMap::new();
let mut functions: FxHashMap<String, Function> = FxHashMap::default();
functions.insert(
"f1".to_string(),
Function {
@ -36,14 +37,14 @@ fn bench_filter_covered_no_functions(b: &mut Bencher) {
let result = CovResult {
lines: [(1, 21), (2, 7), (7, 0)].iter().cloned().collect(),
branches: [].iter().cloned().collect(),
functions: HashMap::new(),
functions: FxHashMap::default(),
};
b.iter(|| black_box(grcov::is_covered(&result)));
}
#[bench]
fn bench_filter_uncovered_no_lines_executed(b: &mut Bencher) {
let mut functions: HashMap<String, Function> = HashMap::new();
let mut functions: FxHashMap<String, Function> = FxHashMap::default();
functions.insert(
"f1".to_string(),
Function {
@ -61,14 +62,14 @@ fn bench_filter_uncovered_no_lines_executed(b: &mut Bencher) {
let result = CovResult {
lines: [(1, 0), (2, 0), (7, 0)].iter().cloned().collect(),
branches: [].iter().cloned().collect(),
functions: HashMap::new(),
functions: FxHashMap::default(),
};
b.iter(|| black_box(grcov::is_covered(&result)));
}
#[bench]
fn bench_filter_covered_functions_executed(b: &mut Bencher) {
let mut functions: HashMap<String, Function> = HashMap::new();
let mut functions: FxHashMap<String, Function> = FxHashMap::default();
functions.insert(
"top-level".to_string(),
Function {
@ -93,7 +94,7 @@ fn bench_filter_covered_functions_executed(b: &mut Bencher) {
#[bench]
fn bench_filter_covered_toplevel_executed(b: &mut Bencher) {
let mut functions: HashMap<String, Function> = HashMap::new();
let mut functions: FxHashMap<String, Function> = FxHashMap::default();
functions.insert(
"top-level".to_string(),
Function {
@ -111,7 +112,7 @@ fn bench_filter_covered_toplevel_executed(b: &mut Bencher) {
#[bench]
fn bench_filter_uncovered_functions_not_executed(b: &mut Bencher) {
let mut functions: HashMap<String, Function> = HashMap::new();
let mut functions: FxHashMap<String, Function> = FxHashMap::default();
functions.insert(
"top-level".to_string(),
Function {

72
benches/lib.rs Normal file
Просмотреть файл

@ -0,0 +1,72 @@
#![feature(test)]
extern crate grcov;
extern crate rustc_hash;
extern crate test;
use grcov::{CovResult, Function};
use rustc_hash::FxHashMap;
use test::{black_box, Bencher};
#[bench]
fn bench_lib_merge_results(b: &mut Bencher) {
let mut functions1: FxHashMap<String, Function> = FxHashMap::default();
functions1.insert(
"f1".to_string(),
Function {
start: 1,
executed: false,
},
);
functions1.insert(
"f2".to_string(),
Function {
start: 2,
executed: false,
},
);
let mut result = CovResult {
lines: [(1, 21), (2, 7), (7, 0)].iter().cloned().collect(),
branches: [
(1, vec![false, false]),
(2, vec![false, true]),
(4, vec![true]),
]
.iter()
.cloned()
.collect(),
functions: functions1,
};
let mut functions2: FxHashMap<String, Function> = FxHashMap::default();
functions2.insert(
"f1".to_string(),
Function {
start: 1,
executed: false,
},
);
functions2.insert(
"f2".to_string(),
Function {
start: 2,
executed: true,
},
);
let result2 = CovResult {
lines: [(1, 21), (3, 42), (4, 7), (2, 0), (8, 0)]
.iter()
.cloned()
.collect(),
branches: [
(1, vec![false, false]),
(2, vec![false, true]),
(3, vec![true]),
]
.iter()
.cloned()
.collect(),
functions: functions2,
};
b.iter(|| black_box(grcov::merge_results(&mut result, result2.clone())));
}

86
benches/reader.rs Normal file
Просмотреть файл

@ -0,0 +1,86 @@
#![feature(test)]
extern crate grcov;
extern crate test;
use grcov::{GcovReaderBuf, GCNO};
use std::path::PathBuf;
use test::{black_box, Bencher};
#[bench]
fn bench_reader_gcno(b: &mut Bencher) {
let mut gcno = GCNO::new();
b.iter(|| {
let file = GcovReaderBuf::from("test/llvm/reader.gcno");
black_box(gcno.read(file).unwrap());
});
}
#[bench]
fn bench_reader_gcda(b: &mut Bencher) {
let mut gcno = GCNO::new();
gcno.read(GcovReaderBuf::from("test/llvm/reader.gcno"))
.unwrap();
b.iter(|| {
let file = GcovReaderBuf::from("test/llvm/reader.gcda");
black_box(gcno.read_gcda(file).unwrap());
});
}
#[bench]
fn bench_reader_gcno_dump(b: &mut Bencher) {
let mut gcno = GCNO::new();
gcno.read(GcovReaderBuf::from("test/llvm/reader.gcno"))
.unwrap();
b.iter(|| {
let mut output = Vec::new();
black_box(
gcno.dump(
&PathBuf::from("test/llvm/reader.c"),
"reader.c",
&mut output,
)
.unwrap(),
);
});
}
#[bench]
fn bench_reader_gcno_gcda_dump(b: &mut Bencher) {
let mut gcno = GCNO::new();
gcno.read(GcovReaderBuf::from("test/llvm/reader.gcno"))
.unwrap();
gcno.read_gcda(GcovReaderBuf::from("test/llvm/reader.gcda"))
.unwrap();
b.iter(|| {
let mut output = Vec::new();
black_box(
gcno.dump(
&PathBuf::from("test/llvm/reader.c"),
"reader.c",
&mut output,
)
.unwrap(),
);
});
}
#[bench]
fn bench_reader_finalize_file(b: &mut Bencher) {
let mut gcno = GCNO::new();
gcno.read(GcovReaderBuf::from("test/llvm/file.gcno"))
.unwrap();
gcno.read_gcda(GcovReaderBuf::from("test/llvm/file.gcda"))
.unwrap();
b.iter(|| black_box(gcno.finalize(true)));
}
#[bench]
fn bench_reader_finalize_file_branch(b: &mut Bencher) {
let mut gcno = GCNO::new();
gcno.read(GcovReaderBuf::from("test/llvm/file_branch.gcno"))
.unwrap();
gcno.read_gcda(GcovReaderBuf::from("test/llvm/file_branch.gcda"))
.unwrap();
b.iter(|| black_box(gcno.finalize(true)));
}

Просмотреть файл

@ -1,5 +1,6 @@
use crossbeam::queue::MsQueue;
use std::collections::{BTreeMap, HashMap};
use rustc_hash::FxHashMap;
use std::collections::BTreeMap;
use std::path::PathBuf;
use std::sync::Mutex;
@ -13,7 +14,7 @@ pub struct Function {
pub struct CovResult {
pub lines: BTreeMap<u32, u64>,
pub branches: BTreeMap<u32, Vec<bool>>,
pub functions: HashMap<String, Function>,
pub functions: FxHashMap<String, Function>,
}
#[derive(Debug, PartialEq, Copy, Clone)]
@ -47,6 +48,6 @@ pub struct WorkItem {
pub type WorkQueue = MsQueue<Option<WorkItem>>;
pub type CovResultMap = HashMap<String, CovResult>;
pub type CovResultMap = FxHashMap<String, CovResult>;
pub type SyncCovResultMap = Mutex<CovResultMap>;
pub type CovResultIter = Box<Iterator<Item = (PathBuf, PathBuf, CovResult)>>;

Просмотреть файл

@ -23,11 +23,11 @@ pub fn is_covered(result: &CovResult) -> bool {
#[cfg(test)]
mod tests {
use super::*;
use std::collections::HashMap;
use rustc_hash::FxHashMap;
#[test]
fn test_covered() {
let mut functions: HashMap<String, Function> = HashMap::new();
let mut functions: FxHashMap<String, Function> = FxHashMap::default();
functions.insert(
"f1".to_string(),
Function {
@ -56,7 +56,7 @@ mod tests {
let result = CovResult {
lines: [(1, 21), (2, 7), (7, 0)].iter().cloned().collect(),
branches: [].iter().cloned().collect(),
functions: HashMap::new(),
functions: FxHashMap::default(),
};
assert!(is_covered(&result));
@ -64,7 +64,7 @@ mod tests {
#[test]
fn test_uncovered_no_lines_executed() {
let mut functions: HashMap<String, Function> = HashMap::new();
let mut functions: FxHashMap<String, Function> = FxHashMap::default();
functions.insert(
"f1".to_string(),
Function {
@ -82,7 +82,7 @@ mod tests {
let result = CovResult {
lines: [(1, 0), (2, 0), (7, 0)].iter().cloned().collect(),
branches: [].iter().cloned().collect(),
functions: HashMap::new(),
functions: FxHashMap::default(),
};
assert!(!is_covered(&result));
@ -90,7 +90,7 @@ mod tests {
#[test]
fn test_covered_functions_executed() {
let mut functions: HashMap<String, Function> = HashMap::new();
let mut functions: FxHashMap<String, Function> = FxHashMap::default();
functions.insert(
"top-level".to_string(),
Function {
@ -116,7 +116,7 @@ mod tests {
#[test]
fn test_covered_toplevel_executed() {
let mut functions: HashMap<String, Function> = HashMap::new();
let mut functions: FxHashMap<String, Function> = FxHashMap::default();
functions.insert(
"top-level".to_string(),
Function {
@ -135,7 +135,7 @@ mod tests {
#[test]
fn test_uncovered_functions_not_executed() {
let mut functions: HashMap<String, Function> = HashMap::new();
let mut functions: FxHashMap<String, Function> = FxHashMap::default();
functions.insert(
"top-level".to_string(),
Function {

Просмотреть файл

@ -9,6 +9,7 @@ extern crate uuid;
extern crate walkdir;
extern crate xml;
extern crate zip;
extern crate rustc_hash;
mod defs;
pub use crate::defs::*;
@ -41,7 +42,7 @@ use std::path::PathBuf;
use walkdir::WalkDir;
// Merge results, without caring about duplicate lines (they will be removed at the end).
fn merge_results(result: &mut CovResult, result2: CovResult) {
pub fn merge_results(result: &mut CovResult, result2: CovResult) {
for (&line_no, &execution_count) in &result2.lines {
match result.lines.entry(line_no) {
btree_map::Entry::Occupied(c) => {
@ -222,13 +223,13 @@ pub fn consumer(
#[cfg(test)]
mod tests {
use super::*;
use std::collections::HashMap;
use rustc_hash::FxHashMap;
use std::fs::File;
use std::sync::{Arc, Mutex};
#[test]
fn test_merge_results() {
let mut functions1: HashMap<String, Function> = HashMap::new();
let mut functions1: FxHashMap<String, Function> = FxHashMap::default();
functions1.insert(
"f1".to_string(),
Function {
@ -255,7 +256,7 @@ mod tests {
.collect(),
functions: functions1,
};
let mut functions2: HashMap<String, Function> = HashMap::new();
let mut functions2: FxHashMap<String, Function> = FxHashMap::default();
functions2.insert(
"f1".to_string(),
Function {
@ -322,7 +323,7 @@ mod tests {
.expect("Failed to open lcov file");
let file = BufReader::new(&f);
let results = parse_lcov(file, false).unwrap();
let result_map: Arc<SyncCovResultMap> = Arc::new(Mutex::new(HashMap::with_capacity(1)));
let result_map: Arc<SyncCovResultMap> = Arc::new(Mutex::new(FxHashMap::with_capacity_and_hasher(1, Default::default())));
add_results(
results,
&result_map,
@ -353,7 +354,7 @@ mod tests {
.expect("Failed to open lcov file");
let file = BufReader::new(&f);
let results = parse_lcov(file, false).unwrap();
let result_map: Arc<SyncCovResultMap> = Arc::new(Mutex::new(HashMap::with_capacity(3)));
let result_map: Arc<SyncCovResultMap> = Arc::new(Mutex::new(FxHashMap::with_capacity_and_hasher(3, Default::default())));
add_results(results, &result_map, &None);
let result_map = Arc::try_unwrap(result_map).unwrap().into_inner().unwrap();

Просмотреть файл

@ -1,13 +1,14 @@
extern crate crossbeam;
extern crate grcov;
extern crate num_cpus;
extern crate rustc_hash;
extern crate serde_json;
extern crate tempfile;
use crossbeam::queue::MsQueue;
use rustc_hash::FxHashMap;
use serde_json::Value;
use std::alloc::System;
use std::collections::HashMap;
use std::fs::{self, File};
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
@ -254,7 +255,7 @@ fn main() {
let tmp_path = tmp_dir.path().to_owned();
assert!(tmp_path.exists());
let result_map: Arc<SyncCovResultMap> = Arc::new(Mutex::new(HashMap::with_capacity(20_000)));
let result_map: Arc<SyncCovResultMap> = Arc::new(Mutex::new(FxHashMap::with_capacity_and_hasher(20_000, Default::default())));
let queue: Arc<WorkQueue> = Arc::new(MsQueue::new());
let path_mapping: Arc<Mutex<Option<Value>>> = Arc::new(Mutex::new(None));

Просмотреть файл

@ -1,4 +1,4 @@
use std::collections::{btree_map, hash_map, BTreeMap, HashMap};
use std::collections::{btree_map, hash_map, BTreeMap};
use std::fmt;
use std::fs::File;
use std::io::{self, BufRead, BufReader, Read};
@ -9,6 +9,8 @@ use std::str;
use xml::attribute::OwnedAttribute;
use xml::reader::{EventReader, XmlEvent};
use rustc_hash::FxHashMap;
use crate::defs::*;
#[derive(Debug)]
@ -110,7 +112,7 @@ pub fn parse_lcov<T: Read>(
let mut cur_file = None;
let mut cur_lines = BTreeMap::new();
let mut cur_branches = BTreeMap::new();
let mut cur_functions = HashMap::new();
let mut cur_functions = FxHashMap::default();
let mut results = Vec::new();
@ -140,7 +142,7 @@ pub fn parse_lcov<T: Read>(
cur_file = None;
cur_lines = BTreeMap::new();
cur_branches = BTreeMap::new();
cur_functions = HashMap::new();
cur_functions = FxHashMap::default();
} else {
let mut key_value = l.splitn(2, ':');
let key = try_next!(key_value, l);
@ -220,7 +222,7 @@ pub fn parse_gcov(gcov_path: &Path) -> Result<Vec<(String, CovResult)>, ParserEr
let mut cur_file = None;
let mut cur_lines = BTreeMap::new();
let mut cur_branches = BTreeMap::new();
let mut cur_functions = HashMap::new();
let mut cur_functions = FxHashMap::default();
let mut results = Vec::new();
let f = File::open(&gcov_path)
@ -260,7 +262,7 @@ pub fn parse_gcov(gcov_path: &Path) -> Result<Vec<(String, CovResult)>, ParserEr
cur_file = Some(value.to_owned());
cur_lines = BTreeMap::new();
cur_branches = BTreeMap::new();
cur_functions = HashMap::new();
cur_functions = FxHashMap::default();
}
"function" => {
let mut f_splits = value.splitn(3, ',');
@ -400,8 +402,8 @@ fn parse_jacoco_report_method<T: Read>(
fn parse_jacoco_report_class<T: Read>(
parser: &mut EventReader<T>,
class_name: &str,
) -> Result<HashMap<String, Function>, ParserError> {
let mut functions: HashMap<String, Function> = HashMap::new();
) -> Result<FxHashMap<String, Function>, ParserError> {
let mut functions: FxHashMap<String, Function> = FxHashMap::default();
loop {
match parser.next() {
@ -430,7 +432,7 @@ fn parse_jacoco_report_package<T: Read>(
parser: &mut EventReader<T>,
package: &str,
) -> Result<Vec<(String, CovResult)>, ParserError> {
let mut results_map: HashMap<String, CovResult> = HashMap::new();
let mut results_map: FxHashMap<String, CovResult> = FxHashMap::default();
loop {
match parser.next() {
@ -483,7 +485,7 @@ fn parse_jacoco_report_package<T: Read>(
}
hash_map::Entry::Vacant(v) => {
v.insert(CovResult {
functions: HashMap::new(),
functions: FxHashMap::default(),
lines,
branches,
});
@ -1500,7 +1502,7 @@ mod tests {
lines.insert(1, 0);
lines.insert(4, 1);
lines.insert(6, 1);
let mut functions: HashMap<String, Function> = HashMap::new();
let mut functions: FxHashMap<String, Function> = FxHashMap::default();
functions.insert(
String::from("hello#<init>"),
Function {
@ -1539,7 +1541,7 @@ mod tests {
for i in vec![5, 10, 14, 15, 18, 22, 23, 25, 27, 31, 34, 37, 44, 49] {
lines.insert(i, 0);
}
let mut functions: HashMap<String, Function> = HashMap::new();
let mut functions: FxHashMap<String, Function> = FxHashMap::default();
for (name, start, executed) in vec![
("Person$InnerClassForPerson#getSomethingElse", 31, false),

Просмотреть файл

@ -1,6 +1,7 @@
use globset::{Glob, GlobSetBuilder};
use rustc_hash::FxHashMap;
use serde_json::Value;
use std::collections::{hash_map, HashMap};
use std::collections::hash_map;
use std::fs;
use std::io;
use std::mem;
@ -136,7 +137,7 @@ fn check_extension(path: &PathBuf, e: &str) -> bool {
}
}
fn map_partial_path(file_to_paths: &HashMap<String, Vec<PathBuf>>, path: PathBuf) -> PathBuf {
fn map_partial_path(file_to_paths: &FxHashMap<String, Vec<PathBuf>>, path: PathBuf) -> PathBuf {
let options = file_to_paths.get(path.file_name().unwrap().to_str().unwrap());
if options.is_none() {
@ -206,7 +207,7 @@ pub fn rewrite_paths(
}
// Traverse source dir and store all paths, reversed.
let mut file_to_paths: HashMap<String, Vec<PathBuf>> = HashMap::new();
let mut file_to_paths: FxHashMap<String, Vec<PathBuf>> = FxHashMap::default();
if let Some(ref source_dir) = source_dir {
for entry in WalkDir::new(&source_dir)
.into_iter()
@ -288,7 +289,7 @@ pub fn rewrite_paths(
#[cfg(test)]
mod tests {
use super::*;
use std::collections::{BTreeMap, HashMap};
use std::collections::BTreeMap;
#[test]
fn test_to_lowercase_first() {
@ -319,7 +320,7 @@ mod tests {
CovResult {
lines: BTreeMap::new(),
branches: BTreeMap::new(),
functions: HashMap::new(),
functions: FxHashMap::default(),
}
}};
}
@ -329,7 +330,7 @@ mod tests {
CovResult {
lines: [(42, 1)].iter().cloned().collect(),
branches: BTreeMap::new(),
functions: HashMap::new(),
functions: FxHashMap::default(),
}
}};
}
@ -339,14 +340,14 @@ mod tests {
CovResult {
lines: [(42, 0)].iter().cloned().collect(),
branches: BTreeMap::new(),
functions: HashMap::new(),
functions: FxHashMap::default(),
}
}};
}
#[test]
fn test_rewrite_paths_basic() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert("main.cpp".to_string(), empty_result!());
let results = rewrite_paths(result_map, None, None, None, false, Vec::new(), None);
let mut count = 0;
@ -362,7 +363,7 @@ mod tests {
#[cfg(unix)]
#[test]
fn test_rewrite_paths_remove_prefix() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert(
"/home/worker/src/workspace/main.cpp".to_string(),
empty_result!(),
@ -389,7 +390,7 @@ mod tests {
#[cfg(windows)]
#[test]
fn test_rewrite_paths_remove_prefix() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert(
"C:\\Users\\worker\\src\\workspace\\main.cpp".to_string(),
empty_result!(),
@ -416,7 +417,7 @@ mod tests {
#[cfg(windows)]
#[test]
fn test_rewrite_paths_remove_prefix_with_slash() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert(
"C:/Users/worker/src/workspace/main.cpp".to_string(),
empty_result!(),
@ -443,7 +444,7 @@ mod tests {
#[cfg(windows)]
#[test]
fn test_rewrite_paths_remove_prefix_with_slash_longer_path() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert(
"C:/Users/worker/src/workspace/main.cpp".to_string(),
empty_result!(),
@ -470,7 +471,7 @@ mod tests {
#[cfg(unix)]
#[test]
fn test_rewrite_paths_ignore_non_existing_files() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert("tests/class/main.cpp".to_string(), empty_result!());
result_map.insert("tests/class/doesntexist.cpp".to_string(), empty_result!());
let results = rewrite_paths(result_map, None, None, None, true, Vec::new(), None);
@ -492,7 +493,7 @@ mod tests {
#[cfg(windows)]
#[test]
fn test_rewrite_paths_ignore_non_existing_files() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert("tests\\class\\main.cpp".to_string(), empty_result!());
result_map.insert("tests\\class\\doesntexist.cpp".to_string(), empty_result!());
let results = rewrite_paths(result_map, None, None, None, true, Vec::new(), None);
@ -510,7 +511,7 @@ mod tests {
#[cfg(unix)]
#[test]
fn test_rewrite_paths_ignore_a_directory() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert("main.cpp".to_string(), empty_result!());
result_map.insert("mydir/prova.h".to_string(), empty_result!());
let results = rewrite_paths(
@ -535,7 +536,7 @@ mod tests {
#[cfg(windows)]
#[test]
fn test_rewrite_paths_ignore_a_directory() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert("main.cpp".to_string(), empty_result!());
result_map.insert("mydir\\prova.h".to_string(), empty_result!());
let results = rewrite_paths(
@ -563,7 +564,7 @@ mod tests {
let mut ignore_dirs = vec!["mydir/*".to_string(), "mydir2/*".to_string()];
for _ in 0..2 {
// we run the test twice, one with ignore_dirs and the other with ignore_dirs.reverse()
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert("main.cpp".to_string(), empty_result!());
result_map.insert("mydir/prova.h".to_string(), empty_result!());
result_map.insert("mydir2/prova.h".to_string(), empty_result!());
@ -594,7 +595,7 @@ mod tests {
let mut ignore_dirs = vec!["mydir/*".to_string(), "mydir2/*".to_string()];
for _ in 0..2 {
// we run the test twice, one with ignore_dirs and the other with ignore_dirs.reverse()
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert("main.cpp".to_string(), empty_result!());
result_map.insert("mydir\\prova.h".to_string(), empty_result!());
result_map.insert("mydir2\\prova.h".to_string(), empty_result!());
@ -622,7 +623,7 @@ mod tests {
#[test]
#[should_panic]
fn test_rewrite_paths_rewrite_path_using_relative_source_directory() {
let result_map: CovResultMap = HashMap::new();
let result_map: CovResultMap = FxHashMap::default();
rewrite_paths(
result_map,
None,
@ -637,7 +638,7 @@ mod tests {
#[cfg(unix)]
#[test]
fn test_rewrite_paths_rewrite_path_using_absolute_source_directory() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert("java/main.java".to_string(), empty_result!());
result_map.insert("test/java/main.java".to_string(), empty_result!());
let results = rewrite_paths(
@ -663,7 +664,7 @@ mod tests {
#[cfg(windows)]
#[test]
fn test_rewrite_paths_rewrite_path_using_absolute_source_directory() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert("java\\main.java".to_string(), empty_result!());
result_map.insert("test\\java\\main.java".to_string(), empty_result!());
let results = rewrite_paths(
@ -689,7 +690,7 @@ mod tests {
#[cfg(unix)]
#[test]
fn test_rewrite_paths_rewrite_path_for_java_and_rust() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert("java/main.java".to_string(), empty_result!());
result_map.insert("main.rs".to_string(), empty_result!());
let results = rewrite_paths(
@ -714,7 +715,7 @@ mod tests {
#[cfg(windows)]
#[test]
fn test_rewrite_paths_rewrite_path_for_java_and_rust() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert("java\\main.java".to_string(), empty_result!());
result_map.insert("main.rs".to_string(), empty_result!());
let results = rewrite_paths(
@ -739,7 +740,7 @@ mod tests {
#[cfg(unix)]
#[test]
fn test_rewrite_paths_rewrite_path_using_absolute_source_directory_and_partial_path() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert("java/main.java".to_string(), empty_result!());
let results = rewrite_paths(
result_map,
@ -764,7 +765,7 @@ mod tests {
#[cfg(windows)]
#[test]
fn test_rewrite_paths_rewrite_path_using_absolute_source_directory_and_partial_path() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert("java\\main.java".to_string(), empty_result!());
let results = rewrite_paths(
result_map,
@ -789,7 +790,7 @@ mod tests {
#[cfg(unix)]
#[test]
fn test_rewrite_paths_rewrite_path_and_remove_prefix() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert(
"/home/worker/src/workspace/class/main.cpp".to_string(),
empty_result!(),
@ -818,7 +819,7 @@ mod tests {
#[cfg(windows)]
#[test]
fn test_rewrite_paths_rewrite_path_and_remove_prefix() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert(
"C:\\Users\\worker\\src\\workspace\\class\\main.cpp".to_string(),
empty_result!(),
@ -846,7 +847,7 @@ mod tests {
#[cfg(unix)]
#[test]
fn test_rewrite_paths_rewrite_path_using_mapping() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert("class/main.cpp".to_string(), empty_result!());
let results = rewrite_paths(
result_map,
@ -870,7 +871,7 @@ mod tests {
#[cfg(windows)]
#[test]
fn test_rewrite_paths_rewrite_path_using_mapping() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert("class\\main.cpp".to_string(), empty_result!());
let results = rewrite_paths(
result_map,
@ -894,7 +895,7 @@ mod tests {
#[cfg(unix)]
#[test]
fn test_rewrite_paths_rewrite_path_using_mapping_and_ignore_non_existing() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert("rewritten/main.cpp".to_string(), empty_result!());
result_map.insert("tests/class/main.cpp".to_string(), empty_result!());
let results = rewrite_paths(
@ -922,7 +923,7 @@ mod tests {
#[cfg(windows)]
#[test]
fn test_rewrite_paths_rewrite_path_using_mapping_and_ignore_non_existing() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert("rewritten\\main.cpp".to_string(), empty_result!());
result_map.insert("tests\\class\\main.cpp".to_string(), empty_result!());
let results = rewrite_paths(
@ -950,7 +951,7 @@ mod tests {
#[cfg(unix)]
#[test]
fn test_rewrite_paths_rewrite_path_using_mapping_and_remove_prefix() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert(
"/home/worker/src/workspace/rewritten/main.cpp".to_string(),
empty_result!(),
@ -979,7 +980,7 @@ mod tests {
#[test]
fn test_rewrite_paths_rewrite_path_using_mapping_and_remove_prefix() {
// Mapping with uppercase disk and prefix with uppercase disk.
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert(
"C:\\Users\\worker\\src\\workspace\\rewritten\\main.cpp".to_string(),
empty_result!(),
@ -1006,7 +1007,7 @@ mod tests {
assert_eq!(count, 1);
// Mapping with lowercase disk and prefix with uppercase disk.
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert(
"C:\\Users\\worker\\src\\workspace\\rewritten\\main.cpp".to_string(),
empty_result!(),
@ -1033,7 +1034,7 @@ mod tests {
assert_eq!(count, 1);
// Mapping with uppercase disk and prefix with lowercase disk.
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert(
"C:\\Users\\worker\\src\\workspace\\rewritten\\main.cpp".to_string(),
empty_result!(),
@ -1060,7 +1061,7 @@ mod tests {
assert_eq!(count, 1);
// Mapping with lowercase disk and prefix with lowercase disk.
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert(
"C:\\Users\\worker\\src\\workspace\\rewritten\\main.cpp".to_string(),
empty_result!(),
@ -1090,7 +1091,7 @@ mod tests {
#[cfg(unix)]
#[test]
fn test_rewrite_paths_rewrite_path_using_mapping_and_source_directory_and_remove_prefix() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert(
"/home/worker/src/workspace/rewritten/main.cpp".to_string(),
empty_result!(),
@ -1118,7 +1119,7 @@ mod tests {
#[cfg(windows)]
#[test]
fn test_rewrite_paths_rewrite_path_using_mapping_and_source_directory_and_remove_prefix() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert(
"C:\\Users\\worker\\src\\workspace\\rewritten\\main.cpp".to_string(),
empty_result!(),
@ -1145,7 +1146,7 @@ mod tests {
#[test]
fn test_rewrite_paths_only_covered() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert("covered.cpp".to_string(), covered_result!());
result_map.insert("uncovered.cpp".to_string(), uncovered_result!());
let results = rewrite_paths(result_map, None, None, None, false, Vec::new(), Some(true));
@ -1161,7 +1162,7 @@ mod tests {
#[test]
fn test_rewrite_paths_only_uncovered() {
let mut result_map: CovResultMap = HashMap::new();
let mut result_map: CovResultMap = FxHashMap::default();
result_map.insert("covered.cpp".to_string(), covered_result!());
result_map.insert("uncovered.cpp".to_string(), uncovered_result!());
let results = rewrite_paths(result_map, None, None, None, false, Vec::new(), Some(false));

Просмотреть файл

@ -1,7 +1,7 @@
extern crate tempfile;
use rustc_hash::FxHashMap;
use std::cell::RefCell;
use std::collections::HashMap;
use std::env;
use std::fs::{self, File};
use std::io::{self, BufReader, Read};
@ -49,7 +49,7 @@ impl Archive {
fn insert_vec<'a>(
&'a self,
filename: String,
map: &RefCell<HashMap<String, Vec<&'a Archive>>>,
map: &RefCell<FxHashMap<String, Vec<&'a Archive>>>,
) {
let mut map = map.borrow_mut();
if map.contains_key(&filename) {
@ -66,11 +66,11 @@ impl Archive {
&'a self,
file: FilePath,
path: &PathBuf,
gcno_stem_archives: &RefCell<HashMap<GCNOStem, &'a Archive>>,
gcda_stem_archives: &RefCell<HashMap<String, Vec<&'a Archive>>>,
infos: &RefCell<HashMap<String, Vec<&'a Archive>>>,
xmls: &RefCell<HashMap<String, Vec<&'a Archive>>>,
linked_files_maps: &RefCell<HashMap<String, &'a Archive>>,
gcno_stem_archives: &RefCell<FxHashMap<GCNOStem, &'a Archive>>,
gcda_stem_archives: &RefCell<FxHashMap<String, Vec<&'a Archive>>>,
infos: &RefCell<FxHashMap<String, Vec<&'a Archive>>>,
xmls: &RefCell<FxHashMap<String, Vec<&'a Archive>>>,
linked_files_maps: &RefCell<FxHashMap<String, &'a Archive>>,
is_llvm: bool,
) {
if let Some(ext) = path.extension() {
@ -153,11 +153,11 @@ impl Archive {
pub fn explore<'a>(
&'a mut self,
gcno_stem_archives: &RefCell<HashMap<GCNOStem, &'a Archive>>,
gcda_stem_archives: &RefCell<HashMap<String, Vec<&'a Archive>>>,
infos: &RefCell<HashMap<String, Vec<&'a Archive>>>,
xmls: &RefCell<HashMap<String, Vec<&'a Archive>>>,
linked_files_maps: &RefCell<HashMap<String, &'a Archive>>,
gcno_stem_archives: &RefCell<FxHashMap<GCNOStem, &'a Archive>>,
gcda_stem_archives: &RefCell<FxHashMap<String, Vec<&'a Archive>>>,
infos: &RefCell<FxHashMap<String, Vec<&'a Archive>>>,
xmls: &RefCell<FxHashMap<String, Vec<&'a Archive>>>,
linked_files_maps: &RefCell<FxHashMap<String, &'a Archive>>,
is_llvm: bool,
) {
match *self.item.borrow() {
@ -294,8 +294,8 @@ impl Archive {
fn gcno_gcda_producer(
tmp_dir: &Path,
gcno_stem_archives: &HashMap<GCNOStem, &Archive>,
gcda_stem_archives: &HashMap<String, Vec<&Archive>>,
gcno_stem_archives: &FxHashMap<GCNOStem, &Archive>,
gcda_stem_archives: &FxHashMap<String, Vec<&Archive>>,
queue: &WorkQueue,
ignore_orphan_gcno: bool,
) {
@ -390,7 +390,7 @@ fn gcno_gcda_producer(
}
fn file_content_producer(
files: &HashMap<String, Vec<&Archive>>,
files: &FxHashMap<String, Vec<&Archive>>,
queue: &WorkQueue,
item_format: ItemFormat,
) {
@ -407,7 +407,7 @@ fn file_content_producer(
}
}
pub fn get_mapping(linked_files_maps: &HashMap<String, &Archive>) -> Option<Vec<u8>> {
pub fn get_mapping(linked_files_maps: &FxHashMap<String, &Archive>) -> Option<Vec<u8>> {
match linked_files_maps.iter().next() {
Some((ref name, archive)) => {
let mut buffer = Vec::new();
@ -478,11 +478,14 @@ pub fn producer(
});
}
let gcno_stems_archives: RefCell<HashMap<GCNOStem, &Archive>> = RefCell::new(HashMap::new());
let gcda_stems_archives: RefCell<HashMap<String, Vec<&Archive>>> = RefCell::new(HashMap::new());
let infos: RefCell<HashMap<String, Vec<&Archive>>> = RefCell::new(HashMap::new());
let xmls: RefCell<HashMap<String, Vec<&Archive>>> = RefCell::new(HashMap::new());
let linked_files_maps: RefCell<HashMap<String, &Archive>> = RefCell::new(HashMap::new());
let gcno_stems_archives: RefCell<FxHashMap<GCNOStem, &Archive>> =
RefCell::new(FxHashMap::default());
let gcda_stems_archives: RefCell<FxHashMap<String, Vec<&Archive>>> =
RefCell::new(FxHashMap::default());
let infos: RefCell<FxHashMap<String, Vec<&Archive>>> = RefCell::new(FxHashMap::default());
let xmls: RefCell<FxHashMap<String, Vec<&Archive>>> = RefCell::new(FxHashMap::default());
let linked_files_maps: RefCell<FxHashMap<String, &Archive>> =
RefCell::new(FxHashMap::default());
for archive in &mut archives {
archive.explore(

Просмотреть файл

@ -1,6 +1,7 @@
use rustc_hash::FxHashMap;
use smallvec::SmallVec;
use std::cmp;
use std::collections::{btree_map, hash_map, BTreeMap, HashMap};
use std::collections::{btree_map, hash_map, BTreeMap};
use std::convert::From;
use std::fmt::{Debug, Display, Formatter};
use std::fs::File;
@ -27,7 +28,7 @@ struct GcovFunction {
name: String,
blocks: SmallVec<[GcovBlock; 16]>,
edges: SmallVec<[GcovEdge; 16]>,
lines: HashMap<u32, u64>,
lines: FxHashMap<u32, u64>,
executed: bool,
}
@ -472,7 +473,7 @@ impl GCNO {
name,
blocks,
edges: SmallVec::new(),
lines: HashMap::new(),
lines: FxHashMap::default(),
executed: false,
};
tag = GCNO::read_edges(&mut fun, reader)?;
@ -611,12 +612,12 @@ impl GCNO {
Ok(())
}
fn collect_lines(&self) -> HashMap<&str, HashMap<u32, u64>> {
let mut results: HashMap<&str, HashMap<u32, u64>> = HashMap::new();
fn collect_lines(&self) -> FxHashMap<&str, FxHashMap<u32, u64>> {
let mut results: FxHashMap<&str, FxHashMap<u32, u64>> = FxHashMap::default();
for function in &self.functions {
let mut lines = match results.entry(&function.file_name) {
hash_map::Entry::Occupied(l) => l.into_mut(),
hash_map::Entry::Vacant(p) => p.insert(HashMap::new()),
hash_map::Entry::Vacant(p) => p.insert(FxHashMap::default()),
};
for (line, counter) in &function.lines {
@ -633,7 +634,7 @@ impl GCNO {
results
}
fn dump(
pub fn dump(
&mut self,
path: &PathBuf,
file_name: &str,
@ -692,7 +693,7 @@ impl GCNO {
}
pub fn finalize(&mut self, branch_enabled: bool) -> Vec<(String, CovResult)> {
let mut results: HashMap<&str, CovResult> = HashMap::new();
let mut results: FxHashMap<&str, CovResult> = FxHashMap::default();
for fun in &mut self.functions {
fun.add_line_count();
let mut res = match results.entry(&fun.file_name) {
@ -700,7 +701,7 @@ impl GCNO {
hash_map::Entry::Vacant(p) => p.insert(CovResult {
lines: BTreeMap::new(),
branches: BTreeMap::new(),
functions: HashMap::new(),
functions: FxHashMap::default(),
}),
};
res.functions.insert(
@ -919,7 +920,7 @@ impl GcovFunction {
fn add_line_count(&mut self) {
self.executed = self.edges.first().unwrap().counter > 0;
if self.executed {
let mut lines_to_block: HashMap<u32, Vec<usize>> = HashMap::new();
let mut lines_to_block: FxHashMap<u32, Vec<usize>> = FxHashMap::default();
for block in &self.blocks {
let n = block.no;
for line in &block.lines {
@ -1080,7 +1081,7 @@ mod tests {
let mut lines: BTreeMap<u32, u64> = BTreeMap::new();
lines.insert(2, 1);
let mut functions: HashMap<String, Function> = HashMap::new();
let mut functions: FxHashMap<String, Function> = FxHashMap::default();
functions.insert(
String::from("main"),
Function {
@ -1136,7 +1137,7 @@ mod tests {
lines.insert(x.0, x.1);
});
let mut functions: HashMap<String, Function> = HashMap::new();
let mut functions: FxHashMap<String, Function> = FxHashMap::default();
functions.insert(
String::from("foo"),
Function {