~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/pack.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-09-04 00:46:17 UTC
  • mfrom: (2776.2.2 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20070904004617-gu4xyzuw6mgesvt7
(robertc) Reduce overhead in pack generation by 25 percent. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
        """
105
105
        current_offset = self.current_offset
106
106
        # Kind marker
107
 
        self.write_func("B")
 
107
        byte_sections = ["B"]
108
108
        # Length
109
 
        self.write_func(str(len(bytes)) + "\n")
 
109
        byte_sections.append(str(len(bytes)) + "\n")
110
110
        # Names
111
111
        for name_tuple in names:
112
112
            # Make sure we're writing valid names.  Note that we will leave a
113
113
            # half-written record if a name is bad!
114
114
            for name in name_tuple:
115
115
                _check_name(name)
116
 
            self.write_func('\x00'.join(name_tuple) + "\n")
 
116
            byte_sections.append('\x00'.join(name_tuple) + "\n")
117
117
        # End of headers
118
 
        self.write_func("\n")
 
118
        byte_sections.append("\n")
119
119
        # Finally, the contents.
120
 
        self.write_func(bytes)
 
120
        byte_sections.append(bytes)
 
121
        # XXX: This causes a memory copy of bytes in size, but is usually
 
122
        # faster than two write calls (12 vs 13 seconds to output a gig of
 
123
        # 1k records.) - results may differ on significantly larger records
 
124
        # like .iso's but as they should be rare in any case and thus not
 
125
        # likely to be the common case. The biggest issue is causing extreme
 
126
        # memory pressure in that case. One possibly improvement here is to
 
127
        # check the size of the content before deciding to join here vs call
 
128
        # write twice.
 
129
        self.write_func(''.join(byte_sections))
121
130
        self.records_written += 1
122
131
        # return a memo of where we wrote data to allow random access.
123
132
        return current_offset, self.current_offset - current_offset