/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: Robert Collins
  • Date: 2006-03-29 18:22:43 UTC
  • mto: (1641.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 1642.
  • Revision ID: robertc@robertcollins.net-20060329182243-c6896e1a73b19e8d
Cache the index number of versions in the knit index's self._cache so that
we do not need to call list.index at all with knits.

Show diffs side-by-side

added added

removed removed

Lines of Context:
860
860
        # only want the _history index to reference the 1st index entry
861
861
        # for version_id
862
862
        if version_id not in self._cache:
 
863
            index = len(self._history)
863
864
            self._history.append(version_id)
864
 
        self._cache[version_id] = (version_id, options, pos, size, parents)
 
865
        else:
 
866
            index = self._cache[version_id][5]
 
867
        self._cache[version_id] = (version_id, 
 
868
                                   options,
 
869
                                   pos,
 
870
                                   size,
 
871
                                   parents,
 
872
                                   index)
865
873
 
866
874
    def __init__(self, transport, filename, mode, create=False):
867
875
        _KnitComponentFile.__init__(self, transport, filename, mode)
916
924
                    # index entry for version_id
917
925
                    version_id = rec[0]
918
926
                    if version_id not in self._cache:
 
927
                        index = len(self._history)
919
928
                        self._history.append(version_id)
 
929
                    else:
 
930
                        index = self._cache[version_id][5]
920
931
                    self._cache[version_id] = (version_id,
921
932
                                               rec[1].split(','),
922
933
                                               int(rec[2]),
923
934
                                               int(rec[3]),
924
 
                                               parents)
 
935
                                               parents,
 
936
                                               index)
925
937
                    # --- self._cache_version 
926
938
            except NoSuchFile, e:
927
939
                if mode != 'w' or not create:
1012
1024
 
1013
1025
    def lookup(self, version_id):
1014
1026
        assert version_id in self._cache
1015
 
        return self._history.index(version_id)
 
1027
        return self._cache[version_id][5]
1016
1028
 
1017
1029
    def _version_list_to_index(self, versions):
1018
1030
        result_list = []
1019
1031
        for version in versions:
1020
1032
            if version in self._cache:
1021
 
                result_list.append(str(self._history.index(version)))
 
1033
                # -- inlined lookup() --
 
1034
                result_list.append(str(self._cache[version][5]))
 
1035
                # -- end lookup () --
1022
1036
            else:
1023
1037
                result_list.append('.' + version.encode('utf-8'))
1024
1038
        return ' '.join(result_list)