comparison rust/hg-cpython/src/parsers.rs @ 45357:27424779c5b8

hg-core: make parse_dirstate return references rather than update hashmaps Returing a vec is faster than updating a hashmap when the hashmap is not needed like in `hg files` which just list tracked files. Returning references avoid copying data when not needed improving performence for large repositories. Differential Revision: https://phab.mercurial-scm.org/D8861
author Antoine Cezar <antoine.cezar@octobus.net>
date Tue, 04 Aug 2020 10:59:43 +0200
parents 26114bd6ec60
children 496537c9c1b4
comparison
equal deleted inserted replaced
45356:f025b97f3758 45357:27424779c5b8
12 use cpython::{ 12 use cpython::{
13 exc, PyBytes, PyDict, PyErr, PyInt, PyModule, PyResult, PyTuple, Python, 13 exc, PyBytes, PyDict, PyErr, PyInt, PyModule, PyResult, PyTuple, Python,
14 PythonObject, ToPyObject, 14 PythonObject, ToPyObject,
15 }; 15 };
16 use hg::{ 16 use hg::{
17 pack_dirstate, parse_dirstate, utils::hg_path::HgPathBuf, 17 pack_dirstate, parse_dirstate, utils::hg_path::HgPathBuf, DirstateEntry,
18 DirstatePackError, DirstateParents, DirstateParseError, FastHashMap, 18 DirstatePackError, DirstateParents, DirstateParseError, FastHashMap,
19 PARENT_SIZE, 19 PARENT_SIZE,
20 }; 20 };
21 use std::convert::TryInto; 21 use std::convert::TryInto;
22 22
27 py: Python, 27 py: Python,
28 dmap: PyDict, 28 dmap: PyDict,
29 copymap: PyDict, 29 copymap: PyDict,
30 st: PyBytes, 30 st: PyBytes,
31 ) -> PyResult<PyTuple> { 31 ) -> PyResult<PyTuple> {
32 let mut dirstate_map = FastHashMap::default(); 32 match parse_dirstate(st.data(py)) {
33 let mut copies = FastHashMap::default(); 33 Ok((parents, entries, copies)) => {
34 let dirstate_map: FastHashMap<HgPathBuf, DirstateEntry> = entries
35 .into_iter()
36 .map(|(path, entry)| (path.to_owned(), entry))
37 .collect();
38 let copy_map: FastHashMap<HgPathBuf, HgPathBuf> = copies
39 .into_iter()
40 .map(|(path, copy)| (path.to_owned(), copy.to_owned()))
41 .collect();
34 42
35 match parse_dirstate(&mut dirstate_map, &mut copies, st.data(py)) {
36 Ok(parents) => {
37 for (filename, entry) in &dirstate_map { 43 for (filename, entry) in &dirstate_map {
38 dmap.set_item( 44 dmap.set_item(
39 py, 45 py,
40 PyBytes::new(py, filename.as_bytes()), 46 PyBytes::new(py, filename.as_bytes()),
41 make_dirstate_tuple(py, entry)?, 47 make_dirstate_tuple(py, entry)?,
42 )?; 48 )?;
43 } 49 }
44 for (path, copy_path) in copies { 50 for (path, copy_path) in copy_map {
45 copymap.set_item( 51 copymap.set_item(
46 py, 52 py,
47 PyBytes::new(py, path.as_bytes()), 53 PyBytes::new(py, path.as_bytes()),
48 PyBytes::new(py, copy_path.as_bytes()), 54 PyBytes::new(py, copy_path.as_bytes()),
49 )?; 55 )?;