Mercurial > hg
comparison mercurial/obsolete.py @ 23790:48284b8f6073
readmarkers: drop temporary substring assignments
Assignments are expensive in inner loops
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sat, 10 Jan 2015 21:24:45 -0600 |
parents | b46876c94a93 |
children | 2e58b062aa35 |
comparison
equal
deleted
inserted
replaced
23789:94951db84fc0 | 23790:48284b8f6073 |
---|---|
288 def _fm1readmarkers(data, off=0): | 288 def _fm1readmarkers(data, off=0): |
289 # Loop on markers | 289 # Loop on markers |
290 l = len(data) | 290 l = len(data) |
291 while off + _fm1fsize <= l: | 291 while off + _fm1fsize <= l: |
292 # read fixed part | 292 # read fixed part |
293 cur = data[off:off + _fm1fsize] | 293 fixeddata = _unpack(_fm1fixed, data[off:off + _fm1fsize]) |
294 off += _fm1fsize | 294 off += _fm1fsize |
295 fixeddata = _unpack(_fm1fixed, cur) | |
296 ttsize, seconds, tz, flags, numsuc, numpar, nummeta, prec = fixeddata | 295 ttsize, seconds, tz, flags, numsuc, numpar, nummeta, prec = fixeddata |
297 # extract the number of parents information | 296 # extract the number of parents information |
298 if numpar == _fm1parentnone: | 297 if numpar == _fm1parentnone: |
299 numpar = None | 298 numpar = None |
300 # build the date tuple (upgrade tz minutes to seconds) | 299 # build the date tuple (upgrade tz minutes to seconds) |
306 fnodesize = _fm1nodesha256size | 305 fnodesize = _fm1nodesha256size |
307 # read replacement | 306 # read replacement |
308 sucs = () | 307 sucs = () |
309 if numsuc: | 308 if numsuc: |
310 s = (fnodesize * numsuc) | 309 s = (fnodesize * numsuc) |
311 cur = data[off:off + s] | 310 sucs = _unpack(_fm1node * numsuc, data[off:off + s]) |
312 sucs = _unpack(_fm1node * numsuc, cur) | |
313 off += s | 311 off += s |
314 # read parents | 312 # read parents |
315 if numpar is None: | 313 if numpar is None: |
316 parents = None | 314 parents = None |
317 elif numpar == 0: | 315 elif numpar == 0: |
318 parents = () | 316 parents = () |
319 elif numpar: # neither None nor zero | 317 elif numpar: # neither None nor zero |
320 s = (fnodesize * numpar) | 318 s = (fnodesize * numpar) |
321 cur = data[off:off + s] | 319 parents = _unpack(_fm1node * numpar, data[off:off + s]) |
322 parents = _unpack(_fm1node * numpar, cur) | |
323 off += s | 320 off += s |
324 # read metadata | 321 # read metadata |
325 metaformat = '>' + (_fm1metapair * nummeta) | 322 metaformat = '>' + (_fm1metapair * nummeta) |
326 s = _fm1metapairsize * nummeta | 323 s = _fm1metapairsize * nummeta |
327 metapairsize = _unpack(metaformat, data[off:off + s]) | 324 metapairsize = _unpack(metaformat, data[off:off + s]) |
328 off += s | 325 off += s |
329 metadata = [] | 326 metadata = [] |
330 for idx in xrange(0, len(metapairsize), 2): | 327 for idx in xrange(0, len(metapairsize), 2): |
331 sk = metapairsize[idx] | 328 sk = metapairsize[idx] |
332 sv = metapairsize[idx + 1] | 329 sv = metapairsize[idx + 1] |
333 key = data[off:off + sk] | 330 metadata.append((data[off:off + sk], data[off + sk:off + sk + sv])) |
334 value = data[off + sk:off + sk + sv] | |
335 assert len(key) == sk | |
336 assert len(value) == sv | |
337 metadata.append((key, value)) | |
338 off += sk + sv | 331 off += sk + sv |
339 metadata = tuple(metadata) | 332 metadata = tuple(metadata) |
340 | 333 |
341 yield (prec, sucs, flags, metadata, date, parents) | 334 yield (prec, sucs, flags, metadata, date, parents) |
342 | 335 |