Patchwork D9098: hg-core: avoid memory allocation (D8958#inline-14990 followup)

login
register
mail settings
Submitter phabricator
Date Sept. 28, 2020, 1:48 p.m.
Message ID <differential-rev-PHID-DREV-onwxbhnmkbmu6373ia5o-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47313/
State Superseded
Headers show

Comments

phabricator - Sept. 28, 2020, 1:48 p.m.
acezar created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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

CHANGE DETAILS




To: acezar, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/rust/hg-core/src/revlog/index.rs b/rust/hg-core/src/revlog/index.rs
--- a/rust/hg-core/src/revlog/index.rs
+++ b/rust/hg-core/src/revlog/index.rs
@@ -131,9 +131,8 @@ 
         if let Some(offset_override) = self.offset_override {
             offset_override
         } else {
-            let mut bytes = [0; 8];
-            bytes[2..8].copy_from_slice(&self.bytes[0..=5]);
-            BigEndian::read_u64(&bytes[..]) as usize
+            ((BigEndian::read_u16(&self.bytes[0..2]) as usize) << 32)
+                + (BigEndian::read_u32(&self.bytes[2..6]) as usize)
         }
     }