-=[ Mr. Bumblebee ]=-
_Indonesia_

Path : /usr/lib/python2.7/dist-packages/bzrlib/
File Upload :
Current File : //usr/lib/python2.7/dist-packages/bzrlib/tuned_gzip.pyc

ó
ô¤áQc@@sdZddlmZddlmZddlZddlmZmZmZm	Z	ddl
Z
ddlZddlZddl
mZddgZd	„Zd
„Zejejejejejejd„Zejejejejejejd„Zdejfd
„ƒYZdS(sIBzrlib specific gzip tunings. We plan to feed these to the upstream gzip.i(tabsolute_import(tStringION(tFEXTRAtFCOMMENTtFNAMEtFHCRC(tsymbol_versioningtGzipFilet
bytes_to_gzipcC@s|dkr|d7}n|S(s‹Return i as an unsigned integer, assuming it fits in 32 bits.

    If it's >= 2GB when viewed as a 32-bit unsigned int, return a long.
    ili l((ti((s5/usr/lib/python2.7/dist-packages/bzrlib/tuned_gzip.pytU32%s
cC@s|d@S(s>Return the low-order 32 bits of an int, as a non-negative int.lÿÿ((R	((s5/usr/lib/python2.7/dist-packages/bzrlib/tuned_gzip.pytLOWU32/scC@s
t|gƒS(s;Create a gzip file containing bytes and return its content.(tchunks_to_gzip(tbytestfactorytleveltmethodtwidthtmemtcrc32((s5/usr/lib/python2.7/dist-packages/bzrlib/tuned_gzip.pyR4sc
C@sÊdg}|||||dƒ}d}	d}
xR|D]J}|||	ƒ}	|
t|ƒ7}
|j|ƒ}|r4|j|ƒq4q4W|j|jƒƒ|jtjdt|	ƒt|
ƒƒƒdj|ƒS(sœCreate a gzip file containing chunks and return its content.

    :param chunks: An iterable of strings. Each string can have arbitrary
        layout.
    s
‹ÿis<LLt(tlentcompresstappendtflushtstructtpackRtjoin(
tchunksRRRRRRtresultRtcrct	total_lentchunktzbytes((s5/usr/lib/python2.7/dist-packages/bzrlib/tuned_gzip.pyR<s
	
(cB@sÈeZdZd„Zejdkr0d„Zn	d„Zd„Zejdkridd	„Zd
„Z	ndd„Zdd
„Zdd„Z
dd„Zd„Zd„ZejdkrÆd„ZnRS(s»Knit tuned version of GzipFile.

    This is based on the following lsprof stats:
    python 2.4 stock GzipFile write:
    58971      0   5644.3090   2721.4730   gzip:193(write)
    +58971     0   1159.5530   1159.5530   +<built-in method compress>
    +176913    0    987.0320    987.0320   +<len>
    +58971     0    423.1450    423.1450   +<zlib.crc32>
    +58971     0    353.1060    353.1060   +<method 'write' of 'cStringIO.
                                            StringO' objects>
    tuned GzipFile write:
    58971      0   4477.2590   2103.1120   bzrlib.knit:1250(write)
    +58971     0   1297.7620   1297.7620   +<built-in method compress>
    +58971     0    406.2160    406.2160   +<zlib.crc32>
    +58971     0    341.9020    341.9020   +<method 'write' of 'cStringIO.
                                            StringO' objects>
    +58971     0    328.2670    328.2670   +<len>


    Yes, its only 1.6 seconds, but they add up.
    cO@s=tjtjdƒdtddƒtjj|||ŽdS(Niiisbzrlib.tuned_gzip.GzipFilet
stacklevel(iii(Rtwarnt
deprecated_intDeprecationWarningtgzipRt__init__(tselftargstkwargs((s5/usr/lib/python2.7/dist-packages/bzrlib/tuned_gzip.pyR'{s

iiicC@s|t|ƒ}tj||jƒd@|_|j|j}|j|||_|j||_|j|_|j||_dS(Nlÿÿ(	RtzlibRRtoffsett
extrastarttextrabuft	extrasizetsize(R(tdatatlen_dataR,((s5/usr/lib/python2.7/dist-packages/bzrlib/tuned_gzip.pyt_add_read_dataƒscC@sUt|ƒ}tj||jƒ|_|j|7_|j|7_|j|7_dS(N(RR+RRR.R/R0(R(R1R2((s5/usr/lib/python2.7/dist-packages/bzrlib/tuned_gzip.pyR3s
cC@s|jjdƒdS(s.A tuned version of gzip._write_gzip_header

        We have some extra constrains that plain Gzip does not.
        1) We want to write the whole blob at once. rather than multiple
           calls to fileobj.write().
        2) We never have a filename
        3) We don't care about the time
        s
‹ÿN(tfileobjtwrite(R(((s5/usr/lib/python2.7/dist-packages/bzrlib/tuned_gzip.pyt_write_gzip_header™s		icC@s|jdkrtd‚n|jr‡|jjdƒ}|dkrNtd‚n|jƒ|j|ƒtjtj	ƒ|_
t|_n|jj|ƒ}|dkr|j|j
j
ƒƒt|j
jƒdkrâtdƒ‚n|j
jdd!|_|jƒtd‚n|j|j
j
|ƒƒ|j
jdkrýt|j
jƒd}|dkrˆ|jj|dƒ|j
jdd!|_n_|dkrØd|ks¯td	ƒ‚n|jj|ƒ}|j
j||_n|j
j|_|jƒt|_ndS(
NsReached EOFi
Riswhat does flush do?iiiøÿÿÿstoo great a seek(R4tNonetEOFErrort_new_membertreadt
_init_readt_read_gzip_headerR+t
decompressobjt	MAX_WBITSt
decompresstFalseR3RRtunused_datatAssertionErrort
_gzip_tailt	_read_eoftseektTrue(R(R0tnext_header_bytestbuftseek_length((s5/usr/lib/python2.7/dist-packages/bzrlib/tuned_gzip.pyt_read²s@	




cC@s˜t|jƒdks$tdƒ‚ntjd|jƒ\}}|t|jƒkrstd|t|jƒf‚n!|t|j	ƒkr”td‚ndS(sðtuned to reduce function calls and eliminate file seeking:
            pass 1:
            reduces lsprof count from 800 to 288
            4168 in 296
            avoid U32 call by using struct format L
            4168 in 200
            is!gzip trailer is incorrect length.s<LLsCRC check failed %d %ds!Incorrect length of data producedN(
RRCRBRtunpackR
RtIOErrorRR0(R(Rtisize((s5/usr/lib/python2.7/dist-packages/bzrlib/tuned_gzip.pyRD÷scC@s€|d
kr!|jjdƒ}n|dd!}|dkrFtd‚nt|dd!ƒ}|dkrqtd‚nt|dd	!ƒ}|t@rÙt|jjd
ƒƒ}|dt|jjd
ƒƒ}|jj|ƒn|t@rx6tr|jjd
ƒ}|s|dkræPqæqæWn|t@r_x6tr[|jjd
ƒ}|sT|dkr)Pq)q)Wn|t	@r||jjdƒnd
S(sqSupply bytes if the minimum header size is already read.

        :param bytes: 10 bytes of header data.
        i
iis‹sNot a gzipped fileiisUnknown compression methodiiitN(
R7R4R:RLtordRRRFRR(R(R
tmagicRtflagtxlents((s5/usr/lib/python2.7/dist-packages/bzrlib/tuned_gzip.pyR<s2	

 
	
	
iÿÿÿÿcC@sq|dkrtj}ng}td|ƒ}x=trl|dkrOdj|ƒS|j|ƒ}t|ƒ}|jdƒ}|dk	rÆ|dkrª||krª|d}qÆ||krÆ|d}qÆn|dksÞ|dkr?|j	||d ƒ||d|j
|_
|||j|_|j||8_dj|ƒS|j	|ƒ||}t||dƒ}q0WdS(	sõTuned to remove buffer length calls in _unread and...

        also removes multiple len(c) calls, inlines _unread,
        total savings - lsprof 5800 to 5300
        phase 2:
        4168 calls in 2233
        8176 calls to read() in 1684
        changing the min chunk size to 200 halved all the cache misses
        leading to a drop to:
        4168 calls in 1977
        4168 call to read() in 1646
        - i.e. just reduced the function call overhead. May be worth
          keeping.
        iiÈRs
iÿÿÿÿiiN(
tsystmaxinttminRFRR:RtfindR7RR.R/R,(R(R0tbufstreadsizetctlen_cR	((s5/usr/lib/python2.7/dist-packages/bzrlib/tuned_gzip.pytreadline9s0	




icC@st|jdƒƒ}|jƒS(Niÿÿÿÿ(RR:t	readlines(R(tsizehinttcontent((s5/usr/lib/python2.7/dist-packages/bzrlib/tuned_gzip.pyR]nscC@sN|dkrt|ƒ}n||j|_||j|_|j|8_dS(sqtuned to remove unneeded len calls.

        because this is such an inner routine in readline, and readline is
        in many inner loops, this has been inlined into readline().

        The len_buf parameter combined with the reduction in len calls dropped
        the lsprof ms count for this routine on my test data from 800 to 200 -
        a 75% saving.
        N(R7RR.R/R,(R(RHtlen_buf((s5/usr/lib/python2.7/dist-packages/bzrlib/tuned_gzip.pyt_unread€s

cC@sÀ|jtjkr3ddl}t|jdƒ‚n|jdkrNtd‚nt	|ƒ}|dkr¼|j
||_
tj||j
ƒ|_
|jj|jj|ƒƒ|j|7_ndS(Nis$write() on read-only GzipFile objects!write() on closed GzipFile object(tmodeR&tWRITEterrnoRLtEBADFR4R7t
ValueErrorRR0R+RRR5RR,(R(R1Rdtdata_len((s5/usr/lib/python2.7/dist-packages/bzrlib/tuned_gzip.pyR5scC@s|jdj|ƒƒdS(NR(R5R(R(tlines((s5/usr/lib/python2.7/dist-packages/bzrlib/tuned_gzip.pyt
writelinesžscC@sK|jdkrdS|jtjkr7|jdM_ntjj|ƒdS(Nlÿÿ(R4R7RbR&RcRRtclose(R(((s5/usr/lib/python2.7/dist-packages/bzrlib/tuned_gzip.pyRj§s
(iii(iiiN(ii(t__name__t
__module__t__doc__R'RTtversion_infoR3R6RJRDR7R<R\R]RaR5RiRj(((s5/usr/lib/python2.7/dist-packages/bzrlib/tuned_gzip.pyRds"		
	E+5		(Rmt
__future__Rt	cStringIORR&RRRRRTRR+tbzrlibRt__all__R
RtcompressobjtZ_DEFAULT_COMPRESSIONtDEFLATEDR>t
DEF_MEM_LEVELRRRR(((s5/usr/lib/python2.7/dist-packages/bzrlib/tuned_gzip.pyt<module>s("	
	

%

Copyright © 2017 || Recoded By Mr.Bumblebee