From 37dc273148df0893053bf5cda0582a23f5c2b2d2 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Fri, 19 Aug 2016 02:39:32 +0900 Subject: Micro-optimizations - Make structs smaller - Introduce Result struct and use it to represent matched items instead of reusing Item struct for that purpose - Avoid unnecessary memory allocation - Avoid growing slice from the initial capacity - Code cleanup --- src/pattern_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/pattern_test.go') diff --git a/src/pattern_test.go b/src/pattern_test.go index 26f92844..30691107 100644 --- a/src/pattern_test.go +++ b/src/pattern_test.go @@ -83,7 +83,7 @@ func TestEqual(t *testing.T) { clearPatternCache() pattern := BuildPattern(true, true, CaseSmart, true, []Range{}, Delimiter{}, []rune("^AbC$")) - match := func(str string, sidxExpected int32, eidxExpected int32) { + match := func(str string, sidxExpected int, eidxExpected int) { res := algo.EqualMatch( pattern.caseSensitive, pattern.forward, util.RunesToChars([]rune(str)), pattern.termSets[0][0].text) if res.Start != sidxExpected || res.End != eidxExpected { @@ -133,10 +133,10 @@ func TestOrigTextAndTransformed(t *testing.T) { transformed: trans}, } pattern.extended = extended - matches := pattern.matchChunk(&chunk) - if matches[0].text.ToString() != "junegunn" || string(*matches[0].origText) != "junegunn.choi" || + matches := pattern.matchChunk(&chunk, nil) // No cache + if matches[0].item.text.ToString() != "junegunn" || string(*matches[0].item.origText) != "junegunn.choi" || matches[0].offsets[0][0] != 0 || matches[0].offsets[0][1] != 5 || - !reflect.DeepEqual(matches[0].transformed, trans) { + !reflect.DeepEqual(matches[0].item.transformed, trans) { t.Error("Invalid match result", matches) } } -- cgit v1.2.3