lkml.org 
[lkml]   [2010]   [Feb]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] scripts: improve checkstack
Turn on strict checking, and get rid of annoying use of prototype.
Fix syntax error in declaration

Use efficient sort algorithm by using schwartzian transform.
http://en.wikipedia.org/wiki/Schwartzian_transform

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>

--- a/scripts/checkstack.pl 2010-02-19 21:57:57.609178016 -0800
+++ b/scripts/checkstack.pl 2010-02-19 22:23:16.038241212 -0800
@@ -21,6 +21,8 @@
#
# TODO : Port to all architectures (one regex per arch)

+use strict;
+
# check for arch
#
# $re is used for two matches:
@@ -104,19 +106,11 @@ my (@stack, $re, $dre, $x, $xs);
}
}

-sub bysize($) {
- my ($asize, $bsize);
- ($asize = $a) =~ s/.*: *(.*)$/$1/;
- ($bsize = $b) =~ s/.*: *(.*)$/$1/;
- $bsize <=> $asize
-}
-
#
# main()
#
my $funcre = qr/^$x* <(.*)>:$/;
-my $func;
-my $file, $lastslash;
+my ($func, $file, $lastslash);

while (my $line = <STDIN>) {
if ($line =~ m/$funcre/) {
@@ -173,4 +167,7 @@ while (my $line = <STDIN>) {
}
}

-print sort bysize @stack;
+# Use Schwartzian transform to sort by last field (size)
+print map { $_->[0] }
+ sort { $b->[1] <=> $a->[1] }
+ map { [$_, /:\t*(\d+)$/] } @stack;

\
 
 \ /
  Last update: 2010-02-20 07:29    [W:0.047 / U:0.052 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site