36
36
from copy import copy
37
37
from enum import Enum
38
38
from typing import (Any , DefaultDict , Dict , List , NamedTuple , Optional ,
39
- Sequence , TextIO , TypeVar , Tuple , Union )
39
+ Sequence , Set , TextIO , TypeVar , Tuple , Union )
40
40
41
41
42
42
Number = Union [int , float ]
@@ -374,8 +374,9 @@ def compare_results(results_old: AnalysisRun, results_new: AnalysisRun,
374
374
375
375
# Quadratic algorithms in this part are fine because 'old' and 'new'
376
376
# are most commonly of size 1.
377
- for a in copy (old ):
378
- for b in copy (new ):
377
+ common : Set [AnalysisDiagnostic ] = set ()
378
+ for a in old :
379
+ for b in new :
379
380
if a .get_issue_identifier () == b .get_issue_identifier ():
380
381
a_path_len = a .get_path_length ()
381
382
b_path_len = b .get_path_length ()
@@ -394,16 +395,22 @@ def compare_results(results_old: AnalysisRun, results_new: AnalysisRun,
394
395
path_difference_data .append (
395
396
a_path_len - b_path_len )
396
397
397
- res .add_common (a )
398
- old .remove (a )
399
- new .remove (b )
398
+ res .add_common (b )
399
+ common .add (a )
400
+
401
+ old = filter_issues (old , common )
402
+ new = filter_issues (new , common )
403
+ common = set ()
400
404
401
- for a in copy ( old ) :
402
- for b in copy ( new ) :
405
+ for a in old :
406
+ for b in new :
403
407
if a .is_similar_to (b ):
404
408
res .add_changed (a , b )
405
- old .remove (a )
406
- new .remove (b )
409
+ common .add (a )
410
+ common .add (b )
411
+
412
+ old = filter_issues (old , common )
413
+ new = filter_issues (new , common )
407
414
408
415
# Whatever is left in 'old' doesn't have a corresponding diagnostic
409
416
# in 'new', so we need to mark it as 'removed'.
@@ -443,6 +450,12 @@ def compare_results(results_old: AnalysisRun, results_new: AnalysisRun,
443
450
return res
444
451
445
452
453
+ def filter_issues (origin : List [AnalysisDiagnostic ],
454
+ to_remove : Set [AnalysisDiagnostic ]) \
455
+ -> List [AnalysisDiagnostic ]:
456
+ return [diag for diag in origin if diag not in to_remove ]
457
+
458
+
446
459
def compute_percentile (values : Sequence [T ], percentile : float ) -> T :
447
460
"""
448
461
Return computed percentile.
0 commit comments