1.1 --- a/iixr/data.py Thu Sep 17 20:10:31 2009 +0200
1.2 +++ b/iixr/data.py Thu Sep 17 21:35:30 2009 +0200
1.3 @@ -18,24 +18,15 @@
1.4 with this program. If not, see <http://www.gnu.org/licenses/>.
1.5 """
1.6
1.7 -try:
1.8 - from vint import vint as _vint
1.9 +vint_cache = {}
1.10
1.11 - def vint(number):
1.12 -
1.13 - "Write 'number' as a variable-length integer."
1.14 +def vint(number):
1.15
1.16 - if number >= 0:
1.17 - return _vint(number)
1.18 - else:
1.19 - raise ValueError, "Number %r is negative." % number
1.20 + "Write 'number' as a variable-length integer."
1.21
1.22 -except ImportError:
1.23 -
1.24 - def vint(number):
1.25 -
1.26 - "Write 'number' as a variable-length integer."
1.27 -
1.28 + try:
1.29 + return vint_cache[number]
1.30 + except KeyError:
1.31 if number >= 0:
1.32
1.33 # Special case: one byte containing a 7-bit number.
1.34 @@ -61,4 +52,7 @@
1.35 else:
1.36 raise ValueError, "Number %r is negative." % number
1.37
1.38 +for i in xrange(0, 1024):
1.39 + vint_cache[i] = vint(i)
1.40 +
1.41 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/setup.py Thu Sep 17 20:10:31 2009 +0200
2.2 +++ b/setup.py Thu Sep 17 21:35:30 2009 +0200
2.3 @@ -1,8 +1,6 @@
2.4 #! /usr/bin/env python
2.5
2.6 -from distutils.core import setup, Extension
2.7 -
2.8 -vint = Extension("vint", ["vint.c"])
2.9 +from distutils.core import setup
2.10
2.11 setup(
2.12 name = "iixr",
2.13 @@ -13,5 +11,4 @@
2.14 version = "0.1",
2.15 py_modules = ["itermerge"],
2.16 packages = ["iixr"],
2.17 - ext_modules = [vint],
2.18 )
3.1 --- a/vint.pyx Thu Sep 17 20:10:31 2009 +0200
3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
3.3 @@ -1,46 +0,0 @@
3.4 -#!/usr/bin/env python
3.5 -
3.6 -"""
3.7 -A variable-length integer encoding implementation in Pyrex.
3.8 -
3.9 -Copyright (C) 2009 Paul Boddie <paul@boddie.org.uk>
3.10 -
3.11 -This program is free software; you can redistribute it and/or modify it under
3.12 -the terms of the GNU General Public License as published by the Free Software
3.13 -Foundation; either version 3 of the License, or (at your option) any later
3.14 -version.
3.15 -
3.16 -This program is distributed in the hope that it will be useful, but WITHOUT ANY
3.17 -WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
3.18 -PARTICULAR PURPOSE. See the GNU General Public License for more details.
3.19 -
3.20 -You should have received a copy of the GNU General Public License along
3.21 -with this program. If not, see <http://www.gnu.org/licenses/>.
3.22 -"""
3.23 -
3.24 -cdef extern from "Python.h":
3.25 - object PyString_FromStringAndSize(char *, int)
3.26 -
3.27 -def vint(int number):
3.28 -
3.29 - cdef char bytes[40] # NOTE: Arbitrary limit.
3.30 - cdef int lsd, i
3.31 -
3.32 - if number < 128:
3.33 - bytes[0] = number
3.34 - s = PyString_FromStringAndSize(bytes, 1)
3.35 - return s
3.36 -
3.37 - i = 0
3.38 - while number != 0:
3.39 - lsd = number & 127
3.40 - number = number >> 7
3.41 - if number != 0:
3.42 - lsd = lsd | 128
3.43 - bytes[i] = lsd
3.44 - i = i + 1
3.45 -
3.46 - s = PyString_FromStringAndSize(bytes, i)
3.47 - return s
3.48 -
3.49 -# vim: tabstop=4 expandtab shiftwidth=4