]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/nm: add -sort=size
authorRob Pike <r@golang.org>
Wed, 8 Jan 2014 23:56:40 +0000 (15:56 -0800)
committerRob Pike <r@golang.org>
Wed, 8 Jan 2014 23:56:40 +0000 (15:56 -0800)
When printing the size, we often want to sort on that key.
Because it's used when looking for large things, make the
sort go from largest to smallest.

Perfect recreation of CL 45150044, which was lost to some blunder.

R=golang-codereviews, gobot, rsc
CC=golang-codereviews
https://golang.org/cl/48500044

src/cmd/nm/doc.go
src/cmd/nm/nm.go

index f40073f7a282fb9e694beb90cad1f92b70ed4a5a..81662f8721888cd9616677d8b9dacafb1bcd62e7 100644 (file)
@@ -31,8 +31,9 @@
 //             for compatibility with other nm commands
 //     -size
 //             print symbol size in decimal between address and type
-//     -sort {address,name,none}
+//     -sort {address,name,none,size}
 //             sort output in the given order (default name)
+//             size orders from largest to smallest
 //     -type
 //             print symbol type after name
 //
index d369a4ab54d3a41f8c8e1e10be85f8e076269030..fdf6ef673e726e259a4dfba9817372587523348a 100644 (file)
@@ -58,7 +58,7 @@ func main() {
        flag.Parse()
 
        switch *sortOrder {
-       case "address", "name", "none":
+       case "address", "name", "none", "size":
                // ok
        default:
                fmt.Fprintf(os.Stderr, "nm: unknown sort order %q\n", *sortOrder)
@@ -135,6 +135,8 @@ HaveSyms:
                sort.Sort(byAddr(syms))
        case "name":
                sort.Sort(byName(syms))
+       case "size":
+               sort.Sort(bySize(syms))
        }
 
        w := bufio.NewWriter(os.Stdout)
@@ -170,3 +172,9 @@ type byName []Sym
 func (x byName) Len() int           { return len(x) }
 func (x byName) Swap(i, j int)      { x[i], x[j] = x[j], x[i] }
 func (x byName) Less(i, j int) bool { return x[i].Name < x[j].Name }
+
+type bySize []Sym
+
+func (x bySize) Len() int           { return len(x) }
+func (x bySize) Swap(i, j int)      { x[i], x[j] = x[j], x[i] }
+func (x bySize) Less(i, j int) bool { return x[i].Size > x[j].Size }