Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbf3e733

Browse files
committed
Apply memoization to getPhases; this provides a decent perf gain
1 parent911cf45 commitbf3e733

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

‎html5lib/html5parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ def parseRCDataRawtext(self, token, contentType):
418418
self.phase=self.phases["text"]
419419

420420

421+
@utils.memoize
421422
defgetPhases(debug):
422423
deflog(function):
423424
"""Logger that records which phase processes each token"""

‎html5lib/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,15 @@ def moduleFactory(baseModule, *args, **kwargs):
109109
returnmod
110110

111111
returnmoduleFactory
112+
113+
114+
defmemoize(func):
115+
cache= {}
116+
117+
defwrapped(*args,**kwargs):
118+
key= (tuple(args),tuple(kwargs.items()))
119+
ifkeynotincache:
120+
cache[key]=func(*args,**kwargs)
121+
returncache[key]
122+
123+
returnwrapped

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp