From 41e916a511f37848168a3cddf7cbd1ea1a9ba8da Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 14 Aug 2016 11:58:47 +0900 Subject: [PATCH] [perf] evaluateBonus can start from sidx - 1 --- src/algo/algo.go | 2 +- src/util/util.go | 11 ++++------- src/util/util_test.go | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/algo/algo.go b/src/algo/algo.go index 9bf476f..63469c9 100644 --- a/src/algo/algo.go +++ b/src/algo/algo.go @@ -55,7 +55,7 @@ func evaluateBonus(caseSensitive bool, text util.Chars, pattern []rune, sidx int lenPattern := len(pattern) consecutive := false prevClass := charNonWord - for index := 0; index < eidx; index++ { + for index := util.Max(0, sidx-1); index < eidx; index++ { char := text.Get(index) var class charClass if unicode.IsLower(char) { diff --git a/src/util/util.go b/src/util/util.go index a95340e..113fee9 100644 --- a/src/util/util.go +++ b/src/util/util.go @@ -10,14 +10,11 @@ import ( ) // Max returns the largest integer -func Max(first int, items ...int) int { - max := first - for _, item := range items { - if item > max { - max = item - } +func Max(first int, second int) int { + if first >= second { + return first } - return max + return second } // Min returns the smallest integer diff --git a/src/util/util_test.go b/src/util/util_test.go index 06cfd4f..d6a03d9 100644 --- a/src/util/util_test.go +++ b/src/util/util_test.go @@ -3,7 +3,7 @@ package util import "testing" func TestMax(t *testing.T) { - if Max(-2, 5, 1, 4, 3) != 5 { + if Max(-2, 5) != 5 { t.Error("Invalid result") } }