projects
/
python-bulletml.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Intern type strings for faster comparison during action running.
[python-bulletml.git]
/
bulletml
/
parser.py
diff --git
a/bulletml/parser.py
b/bulletml/parser.py
index
86dfe3c
..
9d515a2
100644
(file)
--- a/
bulletml/parser.py
+++ b/
bulletml/parser.py
@@
-13,6
+13,12
@@
import math
from xml.etree.ElementTree import ElementTree
from xml.etree.ElementTree import ElementTree
+# Python 3 moved this for no really good reason.
+try:
+ from sys import intern
+except ImportError:
+ pass
+
try:
from io import StringIO
except ImportError:
try:
from io import StringIO
except ImportError:
@@
-64,7
+70,7
@@
class Direction(object):
def __init__(self, type, value):
if type not in self.VALID_TYPES:
raise ValueError("invalid type %r" % type)
def __init__(self, type, value):
if type not in self.VALID_TYPES:
raise ValueError("invalid type %r" % type)
- self.type =
type
+ self.type =
intern(type)
self.value = value
def __getstate__(self):
self.value = value
def __getstate__(self):
@@
-132,7
+138,7
@@
class Speed(object):
def __init__(self, type, value):
if type not in self.VALID_TYPES:
raise ValueError("invalid type %r" % type)
def __init__(self, type, value):
if type not in self.VALID_TYPES:
raise ValueError("invalid type %r" % type)
- self.type =
type
+ self.type =
intern(type)
self.value = value
def __getstate__(self):
self.value = value
def __getstate__(self):
@@
-537,7
+543,7
@@
class Offset(object):
def __init__(self, type, x, y):
if type not in self.VALID_TYPES:
raise ValueError("invalid type %r" % type)
def __init__(self, type, x, y):
if type not in self.VALID_TYPES:
raise ValueError("invalid type %r" % type)
- self.type =
type
+ self.type =
intern(type)
self.x = x
self.y = y
self.x = x
self.y = y
@@
-706,7
+712,7
@@
class BulletML(object):
)
def __init__(self, type="none", actions=None):
)
def __init__(self, type="none", actions=None):
- self.type =
type
+ self.type =
intern(type)
self.actions = [] if actions is None else actions
def __getstate__(self):
self.actions = [] if actions is None else actions
def __getstate__(self):