From e2f0aee9a31591e52d2658b2a243a60eabe02d32 Mon Sep 17 00:00:00 2001 From: Roman Babenko Date: Sat, 3 Aug 2024 13:48:51 +0300 Subject: [PATCH] speedup 5% for long lines --- credsweeper/scanner/scan_type/scan_type.py | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/credsweeper/scanner/scan_type/scan_type.py b/credsweeper/scanner/scan_type/scan_type.py index 8a95df687..a369bb00e 100644 --- a/credsweeper/scanner/scan_type/scan_type.py +++ b/credsweeper/scanner/scan_type/scan_type.py @@ -164,24 +164,24 @@ def _get_candidates(cls, config: Config, rule: Rule, target: AnalysisTarget) -> if config.exclude_lines and target.line_strip in config.exclude_lines: return candidates - line_data_list = cls.get_line_data_list(config=config, - target=target, - pattern=rule.patterns[0], - filters=rule.filters) - - for line_data in line_data_list: - if config.exclude_values and line_data.value.strip() in config.exclude_values: - continue - - candidate = Candidate([line_data], rule.patterns, rule.rule_name, rule.severity, config, rule.validations, - rule.use_ml, rule.confidence) - # single pattern with multiple values means all the patterns must matched in target - if 1 < len(rule.patterns) and rule.rule_type in (RuleType.PATTERN, RuleType.KEYWORD): - # additional check whether all patterns match - if not cls._aux_scan(config, rule, target, candidate): - # cannot find secondary values for the candidate + if line_data_list := cls.get_line_data_list(config=config, + target=target, + pattern=rule.patterns[0], + filters=rule.filters): + for line_data in line_data_list: + if config.exclude_values and line_data.value.strip() in config.exclude_values: continue - candidates.append(candidate) + + candidate = Candidate([line_data], rule.patterns, rule.rule_name, rule.severity, config, + rule.validations, + rule.use_ml, rule.confidence) + # single pattern with multiple values means all the patterns must matched in target + if 1 < len(rule.patterns) and rule.rule_type in (RuleType.PATTERN, RuleType.KEYWORD): + # additional check whether all patterns match + if not cls._aux_scan(config, rule, target, candidate): + # cannot find secondary values for the candidate + continue + candidates.append(candidate) return candidates @classmethod