[Zope-CVS] CVS: Products/ZCTextIndex - WidCode.py:1.1.2.3
Tim Peters
tim.one@comcast.net
Sat, 11 May 2002 00:37:00 -0400
Update of /cvs-repository/Products/ZCTextIndex
In directory cvs.zope.org:/tmp/cvs-serv18469
Modified Files:
Tag: TextIndexDS9-branch
WidCode.py
Log Message:
Changed the _encoding table from a dict to a tuple (it's indexed by all
the ints in range(0x1000) -- no need for a dict here)
=== Products/ZCTextIndex/WidCode.py 1.1.2.2 => 1.1.2.3 ===
def encode(wids):
- # Encode a list of wids as a string
- get = _encoding.get
- return "".join([get(w) or _encode(w) for w in wids])
+ # Encode a list of wids as a string.
+ wid2enc = _encoding
+ n = len(wid2enc)
+ return "".join([w < n and wid2enc[w] or _encode(w) for w in wids])
-_encoding = {} # Filled later
+_encoding = [None] * 0x1000 # Filled later, and converted to a tuple
def _encode(w):
assert 0x1000 <= w < 0x1000000
@@ -88,6 +89,7 @@
return ((a & 0x7) << 21) | (b << 14) | (c << 7) | d
def _fill():
+ global _encoding
for i in range(0x40):
s = chr(i + 0x80)
_encoding[i] = s
@@ -97,6 +99,7 @@
s = chr(hi + 0xC0) + chr(lo)
_encoding[i] = s
_decoding[s] = i
+ _encoding = tuple(_encoding)
_fill()