diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2017-08-19 12:14:48 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2017-08-19 12:14:48 +0900 |
commit | c304fc43333c95467394ca2d6e5eddbbcdf99e3d (patch) | |
tree | 0c9d132b0baa85f8388e8929ed6d7b53229f3ba0 | |
parent | 6977cf268f253f9f0b826b80ade5ced665436cfd (diff) |
Delay slab allocation
-rw-r--r-- | src/algo/algo.go | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/algo/algo.go b/src/algo/algo.go index e98ff1d8..74c4ad5a 100644 --- a/src/algo/algo.go +++ b/src/algo/algo.go @@ -329,6 +329,12 @@ func FuzzyMatchV2(caseSensitive bool, normalize bool, forward bool, input util.C return FuzzyMatchV1(caseSensitive, normalize, forward, input, pattern, withPos, slab) } + // Phase 1. Optimized search for ASCII string + idx := asciiFuzzyIndex(&input, pattern, caseSensitive) + if idx < 0 { + return Result{-1, -1, 0}, nil + } + // Reuse pre-allocated integer slice to avoid unnecessary sweeping of garbages offset16 := 0 offset32 := 0 @@ -339,12 +345,6 @@ func FuzzyMatchV2(caseSensitive bool, normalize bool, forward bool, input util.C // Rune array offset32, T := alloc32(offset32, slab, N, false) - // Phase 1. Optimized search for ASCII string - idx := asciiFuzzyIndex(&input, pattern, caseSensitive) - if idx < 0 { - return Result{-1, -1, 0}, nil - } - // Phase 2. Calculate bonus for each point pidx, lastIdx, prevClass := 0, 0, charNonWord input.CopyRunes(T) |