Skip to content

Commit c4e271a

Browse files
committed
fixup! Only initialize the method dispatcher once
1 parent a4b5234 commit c4e271a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

html5lib/html5parser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,10 @@ def processStartTag(self, token):
457457
func = self.__startTagCache[name]
458458
except KeyError:
459459
func = self.__startTagCache[name] = self.startTagHandler[name]
460+
# bound the cache size in case we get loads of unknown tags
461+
while len(self.__startTagCache) > len(self.startTagHandler) * 1.1:
462+
# this makes the eviction policy random on Py < 3.7 and FIFO >= 3.7
463+
self.__startTagCache.pop(next(iter(self.__startTagCache)))
460464
return func(token)
461465

462466
def startTagHtml(self, token):
@@ -475,6 +479,10 @@ def processEndTag(self, token):
475479
func = self.__endTagCache[name]
476480
except KeyError:
477481
func = self.__endTagCache[name] = self.endTagHandler[name]
482+
# bound the cache size in case we get loads of unknown tagss
483+
while len(self.__endTagCache) > len(self.endTagHandler) * 1.1:
484+
# this makes the eviction policy random on Py < 3.7 and FIFO >= 3.7
485+
self.__endTagCache.pop(next(iter(self.__endTagCache)))
478486
return func(token)
479487

480488
class InitialPhase(Phase):

0 commit comments

Comments
 (0)