2 Commits

Author SHA1 Message Date
codeflash-ai[bot]
7eef3f8fa7
️ Speed up function validate_regex by 162%
Here is an optimized version of the provided Python program. The optimizations focus on improving the I/O operations, avoiding unnecessary checks, and caching the regex pattern validation.



### Explanation of Optimizations.
1. **Caching with `@lru_cache`**: The `validate_regex` function is wrapped with `@lru_cache` to cache the results of previously validated regex patterns. This prevents repeated compilation of the same regex patterns.
2. **Reading the JSON file**: I/O operations were optimized by using the `with` statement to handle file reading and writing.
3. **Avoiding repeated checks**: The unsupported patterns are checked just once per pattern, eliminating redundant operations.
4. **Batch writing**: All rules are collected in a list and written to the output file in a single operation, reducing the overhead of multiple write operations.
2025-02-09 13:59:51 +00:00
fabriziosalmi
e8da4c3d28 nginx snippets generation fix + others minor improvements. 2025-01-16 14:02:19 +01:00