/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: Canonical.com Patch Queue Manager
  • Date: 2007-10-09 04:44:46 UTC
  • mfrom: (2888.1.3 knits)
  • Revision ID: pqm@pqm.ubuntu.com-20071009044446-uliu5z9a52bzmps8
(robertc) Save time when recording full text plain-knit records by using the already joined textual data in _record_to_data. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
886
886
                lines = lines[:]
887
887
                options.append('no-eol')
888
888
                lines[-1] = lines[-1] + '\n'
 
889
                line_bytes += '\n'
889
890
 
890
891
        if delta:
891
892
            # To speed the extract of texts the delta chain is limited
908
909
                store_lines)
909
910
        else:
910
911
            options.append('fulltext')
911
 
            # get mixed annotation + content and feed it into the
912
 
            # serialiser.
913
 
            store_lines = self.factory.lower_fulltext(content)
914
 
            size, bytes = self._data._record_to_data(version_id, digest,
915
 
                store_lines)
 
912
            # isinstance is slower and we have no hierarchy.
 
913
            if self.factory.__class__ == KnitPlainFactory:
 
914
                # Use the already joined bytes saving iteration time in
 
915
                # _record_to_data.
 
916
                size, bytes = self._data._record_to_data(version_id, digest,
 
917
                    lines, [line_bytes])
 
918
            else:
 
919
                # get mixed annotation + content and feed it into the
 
920
                # serialiser.
 
921
                store_lines = self.factory.lower_fulltext(content)
 
922
                size, bytes = self._data._record_to_data(version_id, digest,
 
923
                    store_lines)
916
924
 
917
925
        access_memo = self._data.add_raw_records([size], bytes)[0]
918
926
        self._index.add_versions(
1972
1980
    def _open_file(self):
1973
1981
        return self._access.open_file()
1974
1982
 
1975
 
    def _record_to_data(self, version_id, digest, lines):
 
1983
    def _record_to_data(self, version_id, digest, lines, dense_lines=None):
1976
1984
        """Convert version_id, digest, lines into a raw data block.
1977
1985
        
 
1986
        :param dense_lines: The bytes of lines but in a denser form. For
 
1987
            instance, if lines is a list of 1000 bytestrings each ending in \n,
 
1988
            dense_lines may be a list with one line in it, containing all the
 
1989
            1000's lines and their \n's. Using dense_lines if it is already
 
1990
            known is a win because the string join to create bytes in this
 
1991
            function spends less time resizing the final string.
1978
1992
        :return: (len, a StringIO instance with the raw data ready to read.)
1979
1993
        """
1980
 
        bytes = (''.join(chain(
 
1994
        # Note: using a string copy here increases memory pressure with e.g.
 
1995
        # ISO's, but it is about 3 seconds faster on a 1.2Ghz intel machine
 
1996
        # when doing the initial commit of a mozilla tree. RBC 20070921
 
1997
        bytes = ''.join(chain(
1981
1998
            ["version %s %d %s\n" % (version_id,
1982
1999
                                     len(lines),
1983
2000
                                     digest)],
1984
 
            lines,
1985
 
            ["end %s\n" % version_id])))
 
2001
            dense_lines or lines,
 
2002
            ["end %s\n" % version_id]))
1986
2003
        assert bytes.__class__ == str
1987
2004
        compressed_bytes = bytes_to_gzip(bytes)
1988
2005
        return len(compressed_bytes), compressed_bytes