summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2006-06-04 19:36:28 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2006-06-04 19:36:28 (GMT)
commit3f767795f6784ca6bf797b055be67fce5bf2fa06 (patch)
tree851eea9180023026ef3ef2319fae871a50bb479c /Tools
parent67966bed72dc175938c4b971145c4746ac993f19 (diff)
downloadcpython-3f767795f6784ca6bf797b055be67fce5bf2fa06.zip
cpython-3f767795f6784ca6bf797b055be67fce5bf2fa06.tar.gz
cpython-3f767795f6784ca6bf797b055be67fce5bf2fa06.tar.bz2
Patch #1359618: Speed-up charmap encoder.
Diffstat (limited to 'Tools')
-rw-r--r--Tools/unicode/Makefile2
-rw-r--r--Tools/unicode/gencodec.py51
2 files changed, 27 insertions, 26 deletions
diff --git a/Tools/unicode/Makefile b/Tools/unicode/Makefile
index fbd3557..35744ad 100644
--- a/Tools/unicode/Makefile
+++ b/Tools/unicode/Makefile
@@ -78,7 +78,7 @@ cjk: build/
### Cleanup
clean:
- $(RM) build/*
+ $(RM) -f build/*
distclean: clean
$(RM) -rf MAPPINGS/
diff --git a/Tools/unicode/gencodec.py b/Tools/unicode/gencodec.py
index 0c55de6..8a2ca64 100644
--- a/Tools/unicode/gencodec.py
+++ b/Tools/unicode/gencodec.py
@@ -270,6 +270,11 @@ def codegen(name, map, encodingname, comments=1):
comments=comments,
precisions=(4, 2))
+ if decoding_table_code:
+ suffix = 'table'
+ else:
+ suffix = 'map'
+
l = [
'''\
""" Python Character Mapping Codec %s generated from '%s' with gencodec.py.
@@ -283,30 +288,20 @@ import codecs
class Codec(codecs.Codec):
def encode(self,input,errors='strict'):
- return codecs.charmap_encode(input,errors,encoding_map)
-
- def decode(self,input,errors='strict'):''' % (encodingname, name)
- ]
- if decoding_table_code:
- l.append('''\
- return codecs.charmap_decode(input,errors,decoding_table)''')
- else:
- l.append('''\
- return codecs.charmap_decode(input,errors,decoding_map)''')
+ return codecs.charmap_encode(input,errors,encoding_%s)
- l.append('''
+ def decode(self,input,errors='strict'):
+ return codecs.charmap_decode(input,errors,decoding_%s)
+''' % (encodingname, name, suffix, suffix)]
+ l.append('''\
class IncrementalEncoder(codecs.IncrementalEncoder):
def encode(self, input, final=False):
- return codecs.charmap_encode(input,self.errors,encoding_map)[0]
+ return codecs.charmap_encode(input,self.errors,encoding_%s)[0]
class IncrementalDecoder(codecs.IncrementalDecoder):
- def decode(self, input, final=False):''')
- if decoding_table_code:
- l.append('''\
- return codecs.charmap_decode(input,self.errors,decoding_table)[0]''')
- else:
- l.append('''\
- return codecs.charmap_decode(input,self.errors,decoding_map)[0]''')
+ def decode(self, input, final=False):
+ return codecs.charmap_decode(input,self.errors,decoding_%s)[0]''' %
+ (suffix, suffix))
l.append('''
class StreamWriter(Codec,codecs.StreamWriter):
@@ -319,13 +314,13 @@ class StreamReader(Codec,codecs.StreamReader):
def getregentry():
return codecs.CodecInfo(
- Codec().encode,
- Codec().decode,
name=%r,
- streamwriter=StreamWriter,
- streamreader=StreamReader,
+ encode=Codec().encode,
+ decode=Codec().decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
+ streamreader=StreamReader,
+ streamwriter=StreamWriter,
)
''' % encodingname.replace('_', '-'))
@@ -342,10 +337,16 @@ def getregentry():
l.extend(decoding_table_code)
# Add encoding map
- l.append('''
+ if decoding_table_code:
+ l.append('''
+### Encoding table
+encoding_table=codecs.charmap_build(decoding_table)
+''')
+ else:
+ l.append('''
### Encoding Map
''')
- l.extend(encoding_map_code)
+ l.extend(encoding_map_code)
# Final new-line
l.append('')