~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tuned_gzip.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-14 16:16:53 UTC
  • mto: (1946.2.6 reduce-knit-churn)
  • mto: This revision was merged to the branch mainline in revision 1919.
  • Revision ID: john@arbash-meinel.com-20060814161653-54cdcdadcd4e9003
Remove bogus entry from BRANCH.TODO

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Bzrlib specific gzip tunings. We plan to feed these to the upstream gzip."""
19
19
 
20
 
from cStringIO import StringIO
21
 
 
22
20
# make GzipFile faster:
23
21
import gzip
24
22
from gzip import U32, LOWU32, FEXTRA, FCOMMENT, FNAME, FHCRC
65
63
        self.extrasize += len_data
66
64
        self.size += len_data
67
65
 
68
 
    def _write_gzip_header(self):
69
 
        """A tuned version of gzip._write_gzip_header
70
 
 
71
 
        We have some extra constrains that plain Gzip does not.
72
 
        1) We want to write the whole blob at once. rather than multiple 
73
 
           calls to fileobj.write().
74
 
        2) We never have a filename
75
 
        3) We don't care about the time
76
 
        """
77
 
        self.fileobj.write(
78
 
           '\037\213'   # self.fileobj.write('\037\213')  # magic header
79
 
            '\010'      # self.fileobj.write('\010')      # compression method
80
 
                        # fname = self.filename[:-3]
81
 
                        # flags = 0
82
 
                        # if fname:
83
 
                        #     flags = FNAME
84
 
            '\x00'      # self.fileobj.write(chr(flags))
85
 
            '\0\0\0\0'  # write32u(self.fileobj, long(time.time()))
86
 
            '\002'      # self.fileobj.write('\002')
87
 
            '\377'      # self.fileobj.write('\377')
88
 
                        # if fname:
89
 
            ''          #     self.fileobj.write(fname + '\000')
90
 
            )
91
 
 
92
66
    def _read(self, size=1024):
93
67
        # various optimisations:
94
68
        # reduces lsprof count from 2500 to 
281
255
        # to :
282
256
        # 4168 calls in 417.
283
257
        # Negative numbers result in reading all the lines
284
 
        
285
 
        # python's gzip routine uses sizehint. This is a more efficient way
286
 
        # than python uses to honor it. But it is even more efficient to
287
 
        # just read the entire thing and use cStringIO to split into lines.
288
 
        # if sizehint <= 0:
289
 
        #     sizehint = -1
290
 
        # content = self.read(sizehint)
291
 
        # return bzrlib.osutils.split_lines(content)
292
 
        content = StringIO(self.read(-1))
293
 
        return content.readlines()
 
258
        if sizehint <= 0:
 
259
            sizehint = -1
 
260
        content = self.read(sizehint)
 
261
        return bzrlib.osutils.split_lines(content)
294
262
 
295
263
    def _unread(self, buf, len_buf=None):
296
264
        """tuned to remove unneeded len calls.