diff --git a/pkg/command/command.go b/pkg/command/command.go index 45b40f5..605aca8 100644 --- a/pkg/command/command.go +++ b/pkg/command/command.go @@ -106,6 +106,14 @@ func (c Command) Segments() []string { // Covers returns true if the command is identical or a parent of the given other command. func (c Command) Covers(other Command) bool { + // fast-path, equivalent to the code below (verified with fuzzing) + if !strings.HasPrefix(string(other), string(c)) { + return false + } + return c == separator || len(c) == len(other) || other[len(c)] == separator[0] + + /* ------- + otherSegments := other.Segments() if len(otherSegments) < len(c.Segments()) { return false @@ -116,6 +124,8 @@ func (c Command) Covers(other Command) bool { } } return true + + */ } // String returns the composed representation the command. This is also