use internal, non-caching version of re.compile for extractor patterns
speeds up total compile time of extractor patterns by ~10ms
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
# published by the Free Software Foundation.
|
||||
|
||||
import sys
|
||||
import re
|
||||
from ..util import re_compile
|
||||
|
||||
modules = [
|
||||
"2ch",
|
||||
@@ -234,7 +234,8 @@ def find(url):
|
||||
|
||||
def add(cls):
|
||||
"""Add 'cls' to the list of available extractors"""
|
||||
cls.pattern = re.compile(cls.pattern)
|
||||
if isinstance(cls.pattern, str):
|
||||
cls.pattern = re_compile(cls.pattern)
|
||||
_cache.append(cls)
|
||||
return cls
|
||||
|
||||
@@ -242,9 +243,11 @@ def add(cls):
|
||||
def add_module(module):
|
||||
"""Add all extractors in 'module' to the list of available extractors"""
|
||||
classes = _get_classes(module)
|
||||
for cls in classes:
|
||||
cls.pattern = re.compile(cls.pattern)
|
||||
_cache.extend(classes)
|
||||
if classes:
|
||||
if isinstance(classes[0].pattern, str):
|
||||
for cls in classes:
|
||||
cls.pattern = re_compile(cls.pattern)
|
||||
_cache.extend(classes)
|
||||
return classes
|
||||
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class Extractor():
|
||||
@classmethod
|
||||
def from_url(cls, url):
|
||||
if isinstance(cls.pattern, str):
|
||||
cls.pattern = re.compile(cls.pattern)
|
||||
cls.pattern = util.re_compile(cls.pattern)
|
||||
match = cls.pattern.match(url)
|
||||
return cls(match) if match else None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user