Skip to content
Snippets Groups Projects
Unverified Commit 41e916a5 authored by Junegunn Choi's avatar Junegunn Choi
Browse files

[perf] evaluateBonus can start from sidx - 1

parent d9c8a9a8
No related branches found
No related tags found
No related merge requests found
...@@ -55,7 +55,7 @@ func evaluateBonus(caseSensitive bool, text util.Chars, pattern []rune, sidx int ...@@ -55,7 +55,7 @@ func evaluateBonus(caseSensitive bool, text util.Chars, pattern []rune, sidx int
lenPattern := len(pattern) lenPattern := len(pattern)
consecutive := false consecutive := false
prevClass := charNonWord prevClass := charNonWord
for index := 0; index < eidx; index++ { for index := util.Max(0, sidx-1); index < eidx; index++ {
char := text.Get(index) char := text.Get(index)
var class charClass var class charClass
if unicode.IsLower(char) { if unicode.IsLower(char) {
......
...@@ -10,14 +10,11 @@ import ( ...@@ -10,14 +10,11 @@ import (
) )
// Max returns the largest integer // Max returns the largest integer
func Max(first int, items ...int) int { func Max(first int, second int) int {
max := first if first >= second {
for _, item := range items { return first
if item > max {
max = item
}
} }
return max return second
} }
// Min returns the smallest integer // Min returns the smallest integer
......
...@@ -3,7 +3,7 @@ package util ...@@ -3,7 +3,7 @@ package util
import "testing" import "testing"
func TestMax(t *testing.T) { func TestMax(t *testing.T) {
if Max(-2, 5, 1, 4, 3) != 5 { if Max(-2, 5) != 5 {
t.Error("Invalid result") t.Error("Invalid result")
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment