-
Notifications
You must be signed in to change notification settings - Fork 9
/
rules.go
65 lines (56 loc) · 1.13 KB
/
rules.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"bytes"
"strconv"
)
var ignoredLines = [...]string{
"\t",
"#",
`. `,
`<autogenerated>`,
`typecheck`,
`escwalk:`,
`escflood:`,
`substituting name`,
`not substituting name`,
`<unknown line number>:`,
}
var ignoredContent = [...]string{
`Before inlining`,
`After inlining`,
}
type Stat struct {
Good []string
Bad []string
}
type Stats [statCount][2]int
func (stats Stats) String() string {
r := ""
for i, v := range stats {
if i > 0 {
r += " "
}
r += strconv.Itoa(v[0]) + "/" + strconv.Itoa(v[1])
}
return r
}
func (stats *Stats) Add(line []byte) {
for i, stat := range statSpecs {
for _, keyword := range stat.Good {
if bytes.Contains(line, []byte(keyword)) {
(*stats)[i][0]++
}
}
for _, keyword := range stat.Bad {
if bytes.Contains(line, []byte(keyword)) {
(*stats)[i][1]++
}
}
}
}
const statCount = 3
var statSpecs = [statCount]Stat{
{[]string{"can inline", "inlining call to"}, []string{"cannot inline"}},
{[]string{"does not escape"}, []string{"escapes to heap"}},
{[]string{"bounds check elided"}, []string{"Found IsInBounds", "Found IsSliceInBounds"}},
}