feat(aa-log): speed up log generation.
This commit is contained in:
parent
b4e5837bb9
commit
d1fb9574cb
2 changed files with 30 additions and 30 deletions
|
|
@ -19,6 +19,11 @@ var (
|
|||
`\s*` + Comment + `.*`, ``,
|
||||
`(?m)^(?:[\t\s]*(?:\r?\n|\r))+`, ``,
|
||||
})
|
||||
regHex = map[string]*regexp.Regexp{
|
||||
"name": regexp.MustCompile(`name=[0-9A-F]+`),
|
||||
"comm": regexp.MustCompile(`comm=[0-9A-F]+`),
|
||||
"profile": regexp.MustCompile(`profile=[0-9A-F]+`),
|
||||
}
|
||||
)
|
||||
|
||||
type RegexReplList []RegexRepl
|
||||
|
|
@ -30,7 +35,7 @@ type RegexRepl struct {
|
|||
|
||||
// ToRegexRepl convert slice of regex into a slice of RegexRepl
|
||||
func ToRegexRepl(in []string) RegexReplList {
|
||||
out := make([]RegexRepl, 0)
|
||||
out := make([]RegexRepl, 0, len(in)/2)
|
||||
idx := 0
|
||||
for idx < len(in)-1 {
|
||||
regex, repl := in[idx], in[idx+1]
|
||||
|
|
@ -52,10 +57,7 @@ func (rr RegexReplList) Replace(str string) string {
|
|||
|
||||
// DecodeHexInString decode and replace all hex value in a given string of "key=value" format.
|
||||
func DecodeHexInString(str string) string {
|
||||
toDecode := []string{"name", "comm", "profile"}
|
||||
for _, name := range toDecode {
|
||||
exp := name + `=[0-9A-F]+`
|
||||
re := regexp.MustCompile(exp)
|
||||
for name, re := range regHex {
|
||||
str = re.ReplaceAllStringFunc(str, func(s string) string {
|
||||
hexa := s[len(name)+1:]
|
||||
bs, _ := hex.DecodeString(hexa)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue