Skip to content

Commit 1fca2e8

Browse files
committed
fix quadratic time lookup
1 parent 0980358 commit 1fca2e8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

socketsecurity/core/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def find_files(path: str) -> list:
403403
"""
404404
log.debug("Starting Find Files")
405405
start_time = time.time()
406-
files = []
406+
files = set()
407407
for ecosystem in socket_globs:
408408
patterns = socket_globs[ecosystem]
409409
for file_name in patterns:
@@ -415,7 +415,7 @@ def find_files(path: str) -> list:
415415
glob_files = glob(file_path, recursive=True)
416416
for glob_file in glob_files:
417417
if glob_file not in files:
418-
files.append(glob_file)
418+
files.add(glob_file)
419419
glob_end = time.time()
420420
glob_total_time = glob_end - glob_start
421421
log.debug(f"Glob for pattern {file_path} took {glob_total_time:.2f} seconds")
@@ -424,7 +424,7 @@ def find_files(path: str) -> list:
424424
end_time = time.time()
425425
total_time = end_time - start_time
426426
log.info(f"Found {len(files)} in {total_time:.2f} seconds")
427-
return files
427+
return list(files)
428428

429429
@staticmethod
430430
def create_full_scan(files: list, params: FullScanParams, workspace: str) -> FullScan:
@@ -582,13 +582,13 @@ def compare_sboms(new_scan: list, head_scan: list) -> Diff:
582582
head_packages = Core.create_sbom_dict(head_scan)
583583
new_scan_alerts = {}
584584
head_scan_alerts = {}
585-
consolidated = []
585+
consolidated = set()
586586
for package_id in new_packages:
587587
purl, package = Core.create_purl(package_id, new_packages)
588588
base_purl = f"{purl.ecosystem}/{purl.name}@{purl.version}"
589589
if package_id not in head_packages and package.direct and base_purl not in consolidated:
590590
diff.new_packages.append(purl)
591-
consolidated.append(base_purl)
591+
consolidated.add(base_purl)
592592
new_scan_alerts = Core.create_issue_alerts(package, new_scan_alerts, new_packages)
593593
for package_id in head_packages:
594594
purl, package = Core.create_purl(package_id, head_packages)

0 commit comments

Comments
 (0)