[PATCH 3 of 4] obsstore: prefetch struct.calcsize
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Sat Nov 29 19:57:43 CST 2014
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1417072880 28800
# Wed Nov 26 23:21:20 2014 -0800
# Node ID 0e7fa31502eeb5f3d347541e5c1caea4cb714d92
# Parent d0f3dac4ea2b4aff51946c7db0834aa4e5c3e82a
obsstore: prefetch struct.calcsize
This function is widely used and worth but be at module level. No specific
performance boost is visible, but this is more consistent.
diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -73,10 +73,11 @@ import util, base85, node
import phases
from i18n import _
_pack = struct.pack
_unpack = struct.unpack
+_calcsize = struct.calcsize
_SEEK_END = 2 # os.SEEK_END was introduced in Python 2.5
# the obsolete feature is not mature enough to be enabled by default.
# you have to rely on third party extension extension to enable this.
@@ -141,12 +142,12 @@ usingsha256 = 2
# additional encoding. Keys cannot contain '\0' or ':' and values
# cannot contain '\0'.
_fm0version = 0
_fm0fixed = '>BIB20s'
_fm0node = '20s'
-_fm0fsize = struct.calcsize(_fm0fixed)
-_fm0fnodesize = struct.calcsize(_fm0node)
+_fm0fsize = _calcsize(_fm0fixed)
+_fm0fnodesize = _calcsize(_fm0node)
def _fm0readmarkers(data, off=0):
# Loop on markers
l = len(data)
while off + _fm0fsize <= l:
@@ -274,16 +275,16 @@ def _fm0decodemeta(data):
# - remaining bytes: the metadata, each (key, value) pair after the other.
_fm1version = 1
_fm1fixed = '>IdhHBBB20s'
_fm1nodesha1 = '20s'
_fm1nodesha256 = '32s'
-_fm1fsize = struct.calcsize(_fm1fixed)
+_fm1fsize = _calcsize(_fm1fixed)
_fm1parentnone = 3
_fm1parentshift = 14
_fm1parentmask = (_fm1parentnone << _fm1parentshift)
_fm1metapair = 'BB'
-_fm1metapairsize = struct.calcsize('BB')
+_fm1metapairsize = _calcsize('BB')
def _fm1readmarkers(data, off=0):
# Loop on markers
l = len(data)
while off + _fm1fsize <= l:
@@ -298,11 +299,11 @@ def _fm1readmarkers(data, off=0):
# build the date tuple (upgrade tz minutes to seconds)
date = (seconds, tz * 60)
_fm1node = _fm1nodesha1
if flags & usingsha256:
_fm1node = _fm1nodesha256
- fnodesize = struct.calcsize(_fm1node)
+ fnodesize = _calcsize(_fm1node)
# read replacement
sucs = ()
if numsuc:
s = (fnodesize * numsuc)
cur = data[off:off + s]
@@ -357,11 +358,11 @@ def _fm1encodeonemarker(marker):
tz = date[1]//60
data = [None, date[0], tz, flags, numsuc, numpar, len(metadata), pre]
data.extend(sucs)
if parents is not None:
data.extend(parents)
- totalsize = struct.calcsize(format)
+ totalsize = _calcsize(format)
for key, value in metadata:
lk = len(key)
lv = len(value)
data.append(lk)
data.append(lv)
More information about the Mercurial-devel
mailing list