~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_bencode_c.pyx

  • Committer: Jelmer Vernooij
  • Date: 2009-05-28 07:46:11 UTC
  • mto: (4398.5.1 bencode_serializer)
  • mto: This revision was merged to the branch mainline in revision 4410.
  • Revision ID: jelmer@samba.org-20090528074611-4w6dvaxusbpusiv5
Review feedback from bialix:
* Use constant for int buffer size
* Keep reference to original string object
* Make sure we always change the original string back

Show diffs side-by-side

added added

removed removed

Lines of Context:
210
210
 
211
211
cdef enum:
212
212
    INITSIZE = 1024     # initial size for encoder buffer
 
213
    INT_BUF_SIZE = 32
213
214
 
214
215
 
215
216
cdef class Encoder:
282
283
        @param  x:  value to encode
283
284
        """
284
285
        cdef int n
285
 
        self._ensure_buffer(32)
286
 
        n = snprintf(self.tail, 32, "i%de", x)
 
286
        self._ensure_buffer(INT_BUF_SIZE)
 
287
        n = snprintf(self.tail, INT_BUF_SIZE, "i%de", x)
287
288
        if n < 0:
288
289
            raise MemoryError('int %d too big to encode' % x)
289
290
        self._update_tail(n)