Merge pull request #9 from fabriziosalmi/codeflash/optimize-validate_regex-m6xkx22f

️ Speed up function `validate_regex` by 9,172%
This commit is contained in:
fab 2025-02-09 13:14:25 +01:00 committed by GitHub
commit 1a4a2d4e42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,6 +4,7 @@ import re
import logging
from pathlib import Path
from typing import List, Dict, Optional
from functools import lru_cache
# Configure logging
logging.basicConfig(
@ -46,6 +47,7 @@ def load_owasp_rules(file_path: Path) -> List[Dict]:
logging.error(f"[!] Error loading OWASP rules: {e}")
raise
@lru_cache(maxsize=None)
def validate_regex(pattern: str) -> bool:
"""
Validate regex pattern for HAProxy.