Mercurial > public > mercurial-scm > hg
comparison mercurial/revlog.py @ 31804:726f24123f02
revlog: avoid applying delta chain on cache hit
Previously, revlog.revision(raw=False) may try to apply the delta chain
on _cache hit. That happens if flags are non-empty. This patch makes rawtext
reused so delta chain application is avoided.
"_cache" and "rev" are moved a bit to avoid unnecessary assignments.
author | Jun Wu <quark@fb.com> |
---|---|
date | Sun, 02 Apr 2017 18:40:13 -0700 |
parents | 2be73f9720a8 |
children | 0ab7f469d386 |
comparison
equal
deleted
inserted
replaced
31803:2be73f9720a8 | 31804:726f24123f02 |
---|---|
1266 node = nodeorrev | 1266 node = nodeorrev |
1267 rev = None | 1267 rev = None |
1268 | 1268 |
1269 cachedrev = None | 1269 cachedrev = None |
1270 flags = None | 1270 flags = None |
1271 rawtext = None | |
1271 if node == nullid: | 1272 if node == nullid: |
1272 return "" | 1273 return "" |
1273 if self._cache: | 1274 if self._cache: |
1274 if self._cache[0] == node: | 1275 if self._cache[0] == node: |
1275 # _cache only stores rawtext | 1276 # _cache only stores rawtext |
1281 if flags is None: | 1282 if flags is None: |
1282 flags = self.flags(rev) | 1283 flags = self.flags(rev) |
1283 # no extra flags set, no flag processor runs, text = rawtext | 1284 # no extra flags set, no flag processor runs, text = rawtext |
1284 if flags == REVIDX_DEFAULT_FLAGS: | 1285 if flags == REVIDX_DEFAULT_FLAGS: |
1285 return self._cache[2] | 1286 return self._cache[2] |
1287 # rawtext is reusable. need to run flag processor | |
1288 rawtext = self._cache[2] | |
1286 | 1289 |
1287 cachedrev = self._cache[1] | 1290 cachedrev = self._cache[1] |
1288 | 1291 |
1289 # look up what we need to read | 1292 # look up what we need to read |
1290 rawtext = None | |
1291 if rawtext is None: | 1293 if rawtext is None: |
1292 if rev is None: | 1294 if rev is None: |
1293 rev = self.rev(node) | 1295 rev = self.rev(node) |
1294 | 1296 |
1295 chain, stopped = self._deltachain(rev, stoprev=cachedrev) | 1297 chain, stopped = self._deltachain(rev, stoprev=cachedrev) |
1303 if rawtext is None: | 1305 if rawtext is None: |
1304 rawtext = bytes(bins[0]) | 1306 rawtext = bytes(bins[0]) |
1305 bins = bins[1:] | 1307 bins = bins[1:] |
1306 | 1308 |
1307 rawtext = mdiff.patches(rawtext, bins) | 1309 rawtext = mdiff.patches(rawtext, bins) |
1310 self._cache = (node, rev, rawtext) | |
1308 | 1311 |
1309 if flags is None: | 1312 if flags is None: |
1313 if rev is None: | |
1314 rev = self.rev(node) | |
1310 flags = self.flags(rev) | 1315 flags = self.flags(rev) |
1311 | 1316 |
1312 text, validatehash = self._processflags(rawtext, flags, 'read', raw=raw) | 1317 text, validatehash = self._processflags(rawtext, flags, 'read', raw=raw) |
1313 if validatehash: | 1318 if validatehash: |
1314 self.checkhash(text, node, rev=rev) | 1319 self.checkhash(text, node, rev=rev) |
1315 | 1320 |
1316 self._cache = (node, rev, rawtext) | |
1317 return text | 1321 return text |
1318 | 1322 |
1319 def hash(self, text, p1, p2): | 1323 def hash(self, text, p1, p2): |
1320 """Compute a node hash. | 1324 """Compute a node hash. |
1321 | 1325 |