Patchwork D7792: rust-nodemap: abstracting the indexing

login
register
mail settings
Submitter phabricator
Date Jan. 27, 2020, 3:49 p.m.
Message ID <c4ea1f8819569098492f52ea9075f3e4@localhost.localdomain>
Download mbox | patch
Permalink /patch/44684/
State Not Applicable
Headers show

Comments

phabricator - Jan. 27, 2020, 3:49 p.m.
gracinet updated this revision to Diff 19632.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7792?vs=19325&id=19632

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7792/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7792

AFFECTED FILES
  rust/hg-core/src/revlog/nodemap.rs

CHANGE DETAILS




To: gracinet, #hg-reviewers, kevincox
Cc: durin42, kevincox, mercurial-devel

Patch

diff --git a/rust/hg-core/src/revlog/nodemap.rs b/rust/hg-core/src/revlog/nodemap.rs
--- a/rust/hg-core/src/revlog/nodemap.rs
+++ b/rust/hg-core/src/revlog/nodemap.rs
@@ -17,6 +17,7 @@ 
 };
 use std::fmt;
 use std::ops::Deref;
+use std::ops::Index;
 
 #[derive(Debug, PartialEq)]
 pub enum NodeMapError {
@@ -195,6 +196,14 @@ 
     readonly: Box<dyn Deref<Target = [Block]> + Send>,
 }
 
+impl Index<usize> for NodeTree {
+    type Output = Block;
+
+    fn index(&self, i: usize) -> &Block {
+        &self.readonly[i]
+    }
+}
+
 /// Return `None` unless the `Node` for `rev` has given prefix in `index`.
 fn has_prefix_or_none<'p>(
     idx: &impl RevlogIndex,
@@ -213,6 +222,14 @@ 
 }
 
 impl NodeTree {
+    fn len(&self) -> usize {
+        self.readonly.len()
+    }
+
+    fn is_empty(&self) -> bool {
+        self.len() == 0
+    }
+
     /// Main working method for `NodeTree` searches
     ///
     /// This partial implementation lacks special cases for NULL_REVISION
@@ -220,14 +237,13 @@ 
         &self,
         prefix: NodePrefixRef<'p>,
     ) -> Result<Option<Revision>, NodeMapError> {
-        let blocks: &[Block] = &*self.readonly;
-        if blocks.is_empty() {
+        if self.is_empty() {
             return Ok(None);
         }
-        let mut visit = blocks.len() - 1;
+        let mut visit = self.len() - 1;
         for i in 0..prefix.len() {
             let nybble = prefix.get_nybble(i);
-            match blocks[visit].get(nybble) {
+            match self[visit].get(nybble) {
                 Element::None => return Ok(None),
                 Element::Rev(r) => return Ok(Some(r)),
                 Element::Block(idx) => visit = idx,