comparison rust/hg-core/src/dirstate_tree/path_with_basename.rs @ 47283:2a9ddc8094c7

dirstate-v2: Change the on-disk format to be tree-shaped Nodes are stored not only for tracked files but also for their ancestor directories. A node has "pointers" (byte count from the start of the file) to its direct child nodes. Everything can be accessed with zero copy. Differential Revision: https://phab.mercurial-scm.org/D10722
author Simon Sapin <simon.sapin@octobus.net>
date Wed, 19 May 2021 13:15:00 +0200
parents ecfe0819ada5
children
comparison
equal deleted inserted replaced
47282:ce41ee53263f 47283:2a9ddc8094c7
22 pub fn full_path(&self) -> &T { 22 pub fn full_path(&self) -> &T {
23 &self.full_path 23 &self.full_path
24 } 24 }
25 } 25 }
26 26
27 fn find_base_name_start(full_path: &HgPath) -> usize {
28 if let Some(last_slash_position) =
29 full_path.as_bytes().iter().rposition(|&byte| byte == b'/')
30 {
31 last_slash_position + 1
32 } else {
33 0
34 }
35 }
36
27 impl<T: AsRef<HgPath>> WithBasename<T> { 37 impl<T: AsRef<HgPath>> WithBasename<T> {
28 pub fn new(full_path: T) -> Self { 38 pub fn new(full_path: T) -> Self {
29 let base_name_start = if let Some(last_slash_position) = full_path 39 Self {
30 .as_ref() 40 base_name_start: find_base_name_start(full_path.as_ref()),
31 .as_bytes() 41 full_path,
32 .iter() 42 }
33 .rposition(|&byte| byte == b'/') 43 }
34 { 44
35 last_slash_position + 1 45 pub fn from_raw_parts(full_path: T, base_name_start: usize) -> Self {
36 } else { 46 debug_assert_eq!(
37 0 47 base_name_start,
38 }; 48 find_base_name_start(full_path.as_ref())
49 );
39 Self { 50 Self {
40 base_name_start, 51 base_name_start,
41 full_path, 52 full_path,
42 } 53 }
43 } 54 }
44 55
45 pub fn base_name(&self) -> &HgPath { 56 pub fn base_name(&self) -> &HgPath {
46 HgPath::new( 57 HgPath::new(
47 &self.full_path.as_ref().as_bytes()[self.base_name_start..], 58 &self.full_path.as_ref().as_bytes()[self.base_name_start..],
48 ) 59 )
60 }
61
62 pub fn base_name_start(&self) -> usize {
63 self.base_name_start
49 } 64 }
50 } 65 }
51 66
52 impl<T: AsRef<HgPath>> Borrow<HgPath> for WithBasename<T> { 67 impl<T: AsRef<HgPath>> Borrow<HgPath> for WithBasename<T> {
53 fn borrow(&self) -> &HgPath { 68 fn borrow(&self) -> &HgPath {