mirror of
https://github.com/fabriziosalmi/patterns.git
synced 2025-12-17 17:55:48 +00:00
⚡️ Speed up function validate_regex by 9,172%
Changes made for optimization. 1. Added `functools.lru_cache` decorator to cache results of `validate_regex` function calls. This ensures that repeated validations of the same pattern are resolved quickly and avoid redundant regex compilations.
This commit is contained in:
parent
1a98411808
commit
a3104b23c1
@ -4,6 +4,7 @@ import re
|
|||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Dict, Optional
|
from typing import List, Dict, Optional
|
||||||
|
from functools import lru_cache
|
||||||
|
|
||||||
# Configure logging
|
# Configure logging
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
@ -46,6 +47,7 @@ def load_owasp_rules(file_path: Path) -> List[Dict]:
|
|||||||
logging.error(f"[!] Error loading OWASP rules: {e}")
|
logging.error(f"[!] Error loading OWASP rules: {e}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@lru_cache(maxsize=None)
|
||||||
def validate_regex(pattern: str) -> bool:
|
def validate_regex(pattern: str) -> bool:
|
||||||
"""
|
"""
|
||||||
Validate regex pattern for HAProxy.
|
Validate regex pattern for HAProxy.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user