Skip to content

Commit 1c35bfa

Browse files
committed
fix up some comments and revert the change to utils.py because it made it two times slower
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40336
1 parent 5e5309d commit 1c35bfa

4 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
try:
44
frozenset
55
except NameError:
6-
#Import from the sets module for python 2.3
6+
# Import from the sets module for python 2.3
77
from sets import Set as set
88
from sets import ImmutableSet as frozenset
99

@@ -129,7 +129,7 @@
129129
digits = frozenset(string.digits)
130130
hexDigits = frozenset(string.hexdigits)
131131

132-
#Heading elements need to be ordered
132+
# Heading elements need to be ordered
133133
headingElements = (
134134
"h1",
135135
"h2",

src/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
try:
22
frozenset
33
except NameError:
4-
#Import from the sets module for python 2.3
4+
# Import from the sets module for python 2.3
55
from sets import Set as set
66
from sets import ImmutableSet as frozenset
77

src/tokenizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
try:
22
frozenset
33
except NameError:
4-
#Import from the sets module for python 2.3
4+
# Import from the sets module for python 2.3
55
from sets import Set as set
66
from sets import ImmutableSet as frozenset
77

src/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ class MethodDispatcher(dict):
1919
"""
2020

2121
def __init__(self, items=()):
22+
# Using _dictEntries instead of directly assigning to self is about
23+
# twice as fast. Please do careful performance testing before changing
24+
# anything here.
25+
_dictEntries = []
2226
for name,value in items:
2327
if type(name) in (list, tuple, frozenset, set):
2428
for item in name:
25-
self[item] = value
29+
_dictEntries.append((item, value))
2630
else:
27-
self[name] = value
31+
_dictEntries.append((name, value))
32+
dict.__init__(self, _dictEntries)
2833
self.default = None
2934

3035
def __getitem__(self, key):

0 commit comments

Comments
 (0)