Ticket #198: encode-int.diff

File encode-int.diff, 1.0 KB (added by akaihola, 11 months ago)

Performance patch: replace BufferedByteStream with str in _encode_int()

  • pyamf/amf3.py

     
    17101710    if n > 0x40000000: 
    17111711        raise ValueError, "Out of range" 
    17121712 
    1713     bytes = util.BufferedByteStream() 
     1713    bytes = '' 
    17141714    real_value = None 
    17151715 
    17161716    if n > 0x1fffff: 
    17171717        real_value = n 
    17181718        n >>= 1 
    1719         bytes.write_uchar(0x80 | ((n >> 21) & 0xff)) 
     1719        bytes += chr(0x80 | ((n >> 21) & 0xff)) 
    17201720 
    17211721    if n > 0x3fff: 
    1722         bytes.write_uchar(0x80 | ((n >> 14) & 0xff)) 
     1722        bytes += chr(0x80 | ((n >> 14) & 0xff)) 
    17231723 
    17241724    if n > 0x7f: 
    1725         bytes.write_uchar(0x80 | ((n >> 7) & 0xff)) 
     1725        bytes += chr(0x80 | ((n >> 7) & 0xff)) 
    17261726 
    17271727    if real_value is not None: 
    17281728        n = real_value 
    17291729 
    17301730    if n > 0x1fffff: 
    1731         bytes.write_uchar(n & 0xff) 
     1731        bytes += chr(n & 0xff) 
    17321732    else: 
    1733         bytes.write_uchar(n & 0x7f) 
     1733        bytes += chr(n & 0x7f) 
    17341734 
    1735     return bytes.getvalue() 
     1735    return bytes