Browse Source

Cache suitable regular expressions

This speeds up TestAllURLsMatching.test_no_duplicates by about 8000% at the cost of minimal memory overhead.
rtmp_test
Philipp Hagemeister 12 years ago
parent
commit
79cb25776f
1 changed files with 7 additions and 1 deletions
  1. +7
    -1
      youtube_dl/extractor/common.py

+ 7
- 1
youtube_dl/extractor/common.py View File

@ -77,7 +77,13 @@ class InfoExtractor(object):
@classmethod @classmethod
def suitable(cls, url): def suitable(cls, url):
"""Receives a URL and returns True if suitable for this IE.""" """Receives a URL and returns True if suitable for this IE."""
return re.match(cls._VALID_URL, url) is not None
# This does not use has/getattr intentionally - we want to know whether
# we have cached the regexp for *this* class, whereas getattr would also
# match the superclass
if '_VALID_URL_RE' not in cls.__dict__:
cls._VALID_URL_RE = re.compile(cls._VALID_URL)
return cls._VALID_URL_RE.match(url) is not None
@classmethod @classmethod
def working(cls): def working(cls):


Loading…
Cancel
Save