File tree Expand file tree Collapse file tree 2 files changed +47
-12
lines changed Expand file tree Collapse file tree 2 files changed +47
-12
lines changed Original file line number Diff line number Diff line change 18
18
19
19
package ql
20
20
21
- import "fmt"
21
+ import (
22
+ "strings"
23
+ )
22
24
23
25
// Node represents a node in the abstract syntax tree.
24
26
type Node interface {
@@ -36,7 +38,14 @@ type ParenExpr struct {
36
38
}
37
39
38
40
// String returns a string representation of the parenthesized expression.
39
- func (e * ParenExpr ) String () string { return fmt .Sprintf ("(%s)" , e .Expr .String ()) }
41
+ func (e * ParenExpr ) String () string {
42
+ var b strings.Builder
43
+ b .Grow (len (e .Expr .String ()) + 2 )
44
+ b .WriteString ("(" )
45
+ b .WriteString (e .Expr .String ())
46
+ b .WriteString (")" )
47
+ return b .String ()
48
+ }
40
49
41
50
// BinaryExpr represents an operation between two expressions.
42
51
type BinaryExpr struct {
@@ -47,7 +56,20 @@ type BinaryExpr struct {
47
56
48
57
// String returns a string representation of the binary expression.
49
58
func (e * BinaryExpr ) String () string {
50
- return fmt .Sprintf ("%s %s %s" , e .LHS .String (), e .Op .String (), e .RHS .String ())
59
+ var b strings.Builder
60
+
61
+ lhs := e .LHS .String ()
62
+ op := e .Op .String ()
63
+ rhs := e .RHS .String ()
64
+
65
+ b .Grow (len (lhs ) + len (op ) + len (rhs ) + 2 )
66
+ b .WriteString (lhs )
67
+ b .WriteString (" " )
68
+ b .WriteString (op )
69
+ b .WriteString (" " )
70
+ b .WriteString (rhs )
71
+
72
+ return b .String ()
51
73
}
52
74
53
75
// NotExpr represents an unary not expression.
@@ -56,4 +78,11 @@ type NotExpr struct {
56
78
}
57
79
58
80
// String returns a string representation of the not expression.
59
- func (e * NotExpr ) String () string { return fmt .Sprintf ("(%s)" , e .Expr .String ()) }
81
+ func (e * NotExpr ) String () string {
82
+ var b strings.Builder
83
+ b .Grow (len (e .Expr .String ()) + 2 )
84
+ b .WriteString ("(" )
85
+ b .WriteString (e .Expr .String ())
86
+ b .WriteString (")" )
87
+ return b .String ()
88
+ }
Original file line number Diff line number Diff line change 19
19
package ql
20
20
21
21
import (
22
- "bytes"
23
22
"fmt"
24
23
"github.com/rabbitstack/fibratus/pkg/filter/fields"
25
24
"github.com/rabbitstack/fibratus/pkg/kevent"
@@ -129,16 +128,23 @@ type ListLiteral struct {
129
128
130
129
// String returns a string representation of the literal.
131
130
func (s * ListLiteral ) String () string {
132
- var buf bytes.Buffer
133
- _ , _ = buf .WriteString ("(" )
134
- for idx , tagKey := range s .Values {
131
+ var n int
132
+ for _ , elem := range s .Values {
133
+ n += len (elem ) + 2
134
+ }
135
+
136
+ var b strings.Builder
137
+ b .Grow (n + 2 )
138
+ b .WriteString ("(" )
139
+ for idx , elem := range s .Values {
135
140
if idx != 0 {
136
- _ , _ = buf .WriteString (", " )
141
+ b .WriteString (", " )
137
142
}
138
- _ , _ = buf .WriteString (tagKey )
143
+ b .WriteString (elem )
139
144
}
140
- _ , _ = buf .WriteString (")" )
141
- return buf .String ()
145
+ b .WriteString (")" )
146
+
147
+ return b .String ()
142
148
}
143
149
144
150
// Function represents a function call.
You can’t perform that action at this time.
0 commit comments