view rust/hg-core/src/operations/debugdata.rs @ 52280:f4aede0f01af

rust-manifest: use `memchr` crate for all byte-finding needs While writing a very dumb manifest diffing algorithm for a proof-of-concept I saw that `Manifest::find_by_path` was much slower than I was expecting. It turns out that the Rust stdlib uses slow (all is relative) code when searching for byte positions for reasons ranging from portability, SIMD API stability, nobody doing the work, etc. `memch` is much faster for these purposes, so let's use it. I was measuring ~670ms of profile time in `find_by_path`, after this patch it went down to ~230ms.
author Rapha?l Gom?s <rgomes@octobus.net>
date Tue, 12 Nov 2024 23:20:04 +0100
parents bd8081e9fd62
children a3fa37bdb7ec
line wrap: on
line source

// debugdata.rs
//
// Copyright 2020 Antoine Cezar <antoine.cezar@octobus.net>
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.

use crate::errors::HgError;
use crate::exit_codes;
use crate::repo::Repo;
use crate::revlog::options::default_revlog_options;
use crate::revlog::{Revlog, RevlogError, RevlogType};

/// Dump the contents data of a revision.
pub fn debug_data(
    repo: &Repo,
    revset: &str,
    kind: RevlogType,
) -> Result<Vec<u8>, RevlogError> {
    let index_file = match kind {
        RevlogType::Changelog => "00changelog.i",
        RevlogType::Manifestlog => "00manifest.i",
        _ => {
            return Err(RevlogError::Other(HgError::abort(
                format!("invalid revlog type {}", kind),
                exit_codes::ABORT,
                None,
            )))
        }
    };
    let revlog = Revlog::open(
        &repo.store_vfs(),
        index_file,
        None,
        default_revlog_options(
            repo.config(),
            repo.requirements(),
            RevlogType::Changelog,
        )?,
    )?;
    let rev =
        crate::revset::resolve_rev_number_or_hex_prefix(revset, &revlog)?;
    let data = revlog.get_rev_data_for_checked_rev(rev)?;
    Ok(data.into_owned())
}