720
720
HEADER = "# bzr knit index 7\n"
722
# speed of knit parsing went from 280 ms to 280 ms with slots addition.
723
# __slots__ = ['_cache', '_history', '_transport', '_filename']
722
725
def _cache_version(self, version_id, options, pos, size, parents):
723
val = (version_id, options, pos, size, parents)
726
"""Cache a version record in the history array and index cache.
728
This is inlined into __init__ for performance. KEEP IN SYNC.
729
(It saves 60ms, 25% of the __init__ overhead on local 4000 record
724
732
# only want the _history index to reference the 1st index entry
726
if not version_id in self._cache:
734
if version_id not in self._cache:
727
735
self._history.append(version_id)
728
self._cache[version_id] = val
730
def _iter_index(self, fp):
736
#for l in lines.splitlines(False):
736
self._cache[version_id] = (version_id, options, pos, size, parents)
739
738
def __init__(self, transport, filename, mode, create=False):
740
739
_KnitComponentFile.__init__(self, transport, filename, mode)
752
751
pb.update('read knit index', count, total)
753
752
fp = self._transport.get(self._filename)
754
753
self.check_header(fp)
755
for rec in self._iter_index(fp):
754
# readlines reads the whole file at once:
755
# bad for transports like http, good for local disk
756
# we save 60 ms doing this one change (
757
# from calling readline each time to calling
759
# probably what we want for nice behaviour on
760
# http is a incremental readlines that yields, or
761
# a check for local vs non local indexes,
762
for l in fp.readlines():
758
pb.update('read knit index', count, total)
759
parents = self._parse_parents(rec[4:])
760
self._cache_version(rec[0], rec[1].split(','), int(rec[2]), int(rec[3]),
766
#pb.update('read knit index', count, total)
767
# See self._parse_parents
769
for value in rec[4:]:
771
# uncompressed reference
772
parents.append(value[1:])
774
# this is 15/4000ms faster than isinstance,
776
# this function is called thousands of times a
777
# second so small variations add up.
778
assert value.__class__ is str
779
parents.append(self._history[int(value)])
780
# end self._parse_parents
781
# self._cache_version(rec[0],
786
# --- self._cache_version
787
# only want the _history index to reference the 1st
788
# index entry for version_id
790
if version_id not in self._cache:
791
self._history.append(version_id)
792
self._cache[version_id] = (version_id,
797
# --- self._cache_version
762
798
except NoSuchFile, e:
763
799
if mode != 'w' or not create:
773
809
ints are looked up in the index.
774
810
.FOO values are ghosts and converted in to FOO.
812
NOTE: the function is retained here for clarity, and for possible
813
use in partial index reads. However bulk processing now has
814
it inlined in __init__ for inner-loop optimisation.
777
817
for value in compressed_parents:
778
818
if value[-1] == '.':
819
# uncompressed reference
779
820
result.append(value[1:])
781
822
# this is 15/4000ms faster than isinstance,