From 4b566d8310d2216990ce7f3af813313b9776176a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 13 Jan 2026 00:13:59 +0100 Subject: [PATCH] top-complexity: always show the top-25 Accept argument as a custom amount. Previously it showed all functions with a complexity score above 57. This way it adapts better as we gradually decrease complexity in functions. Closes #20273 --- scripts/top-complexity | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/scripts/top-complexity b/scripts/top-complexity index cd132697f7..6cfd58c73f 100755 --- a/scripts/top-complexity +++ b/scripts/top-complexity @@ -81,8 +81,8 @@ my %whitelist = ( # functions with complexity above this level causes the function to return error my $cutoff = 70; -# functions above this complexity level are shown -my $show = 57; +# show this many from the top +my $top = $ARGV[0] ? $ARGV[0] : 25; my $error = 0; my %where; @@ -96,18 +96,17 @@ for my $l (@output) { if($l =~/^(\d+)\t\d+\t\d+\t\d+\t(\d+)\t([^\(]+).*: ([^ ]*)/) { my ($score, $len, $path, $func)=($1, $2, $3, $4); - if($score > $show) { - my $allow = 0; - if($whitelist{$func} && - ($score <= $whitelist{$func})) { - $allow = 1; - } - $where{"$path:$func"}=$score; - $perm{"$path:$func"}=$allow; - if(($score > $cutoff) && !$allow) { - $error++; - } + my $allow = 0; + if($whitelist{$func} && + ($score <= $whitelist{$func})) { + $allow = 1; } + $where{"$path:$func"}=$score; + $perm{"$path:$func"}=$allow; + if(($score > $cutoff) && !$allow) { + $error++; + } + $alllines += $len; $allscore += ($len * $score); } @@ -123,6 +122,9 @@ for my $e (sort {$where{$b} <=> $where{$a}} keys %where) { } printf "%-5d %s%s\n", $where{$e}, $e, $perm{$e} ? " [ALLOWED]": ""; + if(!--$top) { + last; + } } printf "\nAverage complexity: %.2f\n", $allscore / $alllines;