Skip to content

Commit 3ea5452

Browse files
committed
Optimize no yaml needed case
1 parent 9ac35ac commit 3ea5452

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pkg/grep.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ type Selector struct {
1616
InvertRegex bool
1717
}
1818

19+
func (s Selector) MatchesAll() bool {
20+
return len(s.Resources) == 0 && s.Regex == nil
21+
}
22+
1923
type Resource struct {
2024
Name string
2125
Namespace string
@@ -124,6 +128,15 @@ func GrepResources(sel Selector, in io.Reader, out io.Writer, mode DisplayMode)
124128
if err != nil {
125129
return fmt.Errorf("failed to read document: %v", err)
126130
}
131+
// Optimization: Do not do YAML marshal if not needed
132+
if sel.MatchesAll() && mode == Full {
133+
if !first {
134+
fmt.Fprint(out, "---\n")
135+
}
136+
output(string(text))
137+
first = false
138+
continue
139+
}
127140
obj := KubernetesObject{}
128141
if err := yaml.Unmarshal(text, &obj); err != nil {
129142
return fmt.Errorf("failed to unmarshal yaml (%v): %v", text, err)

0 commit comments

Comments
 (0)