Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b8b7201

Browse files
committed
Make indentation slightly faster.
1 parent bae72c0 commit b8b7201

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/matplotlib/backends/backend_svg.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def __init__(self, file):
9393
self.__open = 0 # true if start tag is open
9494
self.__tags = []
9595
self.__data = []
96+
self.__indentation = u" " * 64
9697

9798
def __flush(self, indent=True):
9899
# flush internal buffers
@@ -122,7 +123,7 @@ def start(self, tag, attrib={}, **extra):
122123
tag = escape_cdata(tag)
123124
self.__data = []
124125
self.__tags.append(tag)
125-
self.__write(u" " * (len(self.__tags) - 1))
126+
self.__write(self.__indentation[:len(self.__tags) - 1])
126127
self.__write(u"<%s" % tag)
127128
if attrib or extra:
128129
attrib = attrib.copy()
@@ -144,7 +145,7 @@ def start(self, tag, attrib={}, **extra):
144145

145146
def comment(self, comment):
146147
self.__flush()
147-
self.__write(u" " * (len(self.__tags)))
148+
self.__write(self.__indentation[:len(self.__tags)])
148149
self.__write(u"<!-- %s -->\n" % escape_cdata(comment))
149150

150151
##
@@ -177,7 +178,7 @@ def end(self, tag=None, indent=True):
177178
self.__write(u"/>\n")
178179
return
179180
if indent:
180-
self.__write(u" " * (len(self.__tags)))
181+
self.__write(self.__indentation[:len(self.__tags)])
181182
self.__write(u"</%s>\n" % tag)
182183

183184
##

0 commit comments

Comments
 (0)