Gzip gob files.
[lightning.git] / annotate.go
index 449e64bb3449906e561cb583b0fe77caa6a8dbca..ff4ab887175cfb64c43af6ae6afd93da35399ec8 100644 (file)
@@ -109,10 +109,10 @@ func (cmd *annotatecmd) RunCommand(prog string, args []string, stdin io.Reader,
        bufw := bufio.NewWriter(output)
 
        tilelib := &tileLibrary{
-               includeNoCalls:      true,
+               retainNoCalls:       true,
                retainTileSequences: true,
        }
-       err = tilelib.LoadGob(context.Background(), input, nil)
+       err = tilelib.LoadGob(context.Background(), input, strings.HasSuffix(*inputFilename, ".gz"), nil)
        if err != nil {
                return 1
        }
@@ -152,7 +152,7 @@ func (cmd *annotatecmd) exportTileDiffs(outw io.Writer, tilelib *tileLibrary) er
        sort.Strings(refs)
        log.Infof("len(refs) %d", len(refs))
 
-       outch := make(chan string, 1)
+       outch := make(chan string, runtime.NumCPU()*2)
        var outwg sync.WaitGroup
        defer outwg.Wait()
        outwg.Add(1)
@@ -169,7 +169,7 @@ func (cmd *annotatecmd) exportTileDiffs(outw io.Writer, tilelib *tileLibrary) er
                nseqs += len(refcs)
        }
 
-       throttle := &throttle{Max: runtime.NumCPU() + nseqs + 1}
+       throttle := &throttle{Max: runtime.NumCPU()*2 + nseqs*2 + 1}
        defer throttle.Wait()
 
        for _, refname := range refs {
@@ -185,7 +185,7 @@ func (cmd *annotatecmd) exportTileDiffs(outw io.Writer, tilelib *tileLibrary) er
                        throttle.Acquire()
                        go func() {
                                defer throttle.Release()
-                               throttle.Report(cmd.annotateSequence(throttle, outch, tilelib, taglen, refname, seqname, refcs[seqname]))
+                               throttle.Report(cmd.annotateSequence(throttle, outch, tilelib, taglen, refname, seqname, refcs[seqname], len(refs) > 1))
                        }()
                }
        }
@@ -193,7 +193,7 @@ func (cmd *annotatecmd) exportTileDiffs(outw io.Writer, tilelib *tileLibrary) er
        return throttle.Err()
 }
 
-func (cmd *annotatecmd) annotateSequence(throttle *throttle, outch chan<- string, tilelib *tileLibrary, taglen int, refname, seqname string, reftiles []tileLibRef) error {
+func (cmd *annotatecmd) annotateSequence(throttle *throttle, outch chan<- string, tilelib *tileLibrary, taglen int, refname, seqname string, reftiles []tileLibRef, refnamecol bool) error {
        var refseq []byte
        // tilestart[123] is the index into refseq
        // where the tile for tag 123 was placed.
@@ -232,7 +232,9 @@ func (cmd *annotatecmd) annotateSequence(throttle *throttle, outch chan<- string
                for variant := 1; variant <= len(tvs); variant++ {
                        variant, hash := tileVariantID(variant), tvs[variant-1]
                        tileseq := tilelib.TileVariantSequence(tileLibRef{Tag: tag, Variant: variant})
-                       if len(tileseq) < taglen {
+                       if len(tileseq) == 0 {
+                               continue
+                       } else if len(tileseq) < taglen {
                                return fmt.Errorf("tilevar %d,%d has sequence len %d < taglen %d", tag, variant, len(tileseq), taglen)
                        }
                        var refpart []byte
@@ -273,7 +275,11 @@ func (cmd *annotatecmd) annotateSequence(throttle *throttle, outch chan<- string
                                        } else {
                                                varid = fmt.Sprintf("%d", variant)
                                        }
-                                       outch <- fmt.Sprintf("%d\t%s\t%s\t%s:g.%s\n", tag, varid, refname, seqname, diff.String())
+                                       refnamefield := ""
+                                       if refnamecol {
+                                               refnamefield = "\t" + refname
+                                       }
+                                       outch <- fmt.Sprintf("%d\t%s%s\t%s:g.%s\n", tag, varid, refnamefield, seqname, diff.String())
                                }
                        }()
                }