From af4b301eec655e3149259504ce97738e015317d7 Mon Sep 17 00:00:00 2001 From: "s.kamardin" Date: Wed, 13 Jan 2016 20:26:39 +0300 Subject: [PATCH] Use Len too --- compiler.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/compiler.go b/compiler.go index dea1839..381e9a7 100644 --- a/compiler.go +++ b/compiler.go @@ -194,7 +194,18 @@ func convertMatchers(matchers []match.Matcher) []match.Matcher { for l := 0; l < len(matchers); l++ { for r := len(matchers); r > l; r-- { if glued := glueMatchers(matchers[l:r]); glued != nil { - if done == nil || count < r-l { + var swap bool + + if done == nil { + swap = true + } else { + cl, gl := done.Len(), glued.Len() + swap = cl > -1 && gl > -1 && gl > cl + + swap = swap || count < r-l + } + + if swap { done = glued left = l right = r