summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-07-20 02:44:30 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-07-20 02:44:30 +0900
commitc9f16b6430f3b9c9d12ee078e2218e8467c13340 (patch)
treeb0d7e33da2d605696d98da98e1691bf8d89437de /src/util
parentbc9d2abdb67639e06f7002b278341fb498b79456 (diff)
Avoid unconditionally storsing input as runes
When --with-nth is used, fzf used to preprocess each line and store the result as rune array, which was wasteful if the line only contains ascii characters.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/chars.go43
-rw-r--r--src/util/chars_test.go26
2 files changed, 0 insertions, 69 deletions
diff --git a/src/util/chars.go b/src/util/chars.go
index 5e702004..61e93411 100644
--- a/src/util/chars.go
+++ b/src/util/chars.go
@@ -157,46 +157,3 @@ func (chars *Chars) CopyRunes(dest []rune) {
}
return
}
-
-func (chars *Chars) Slice(b int, e int) Chars {
- if runes := chars.optionalRunes(); runes != nil {
- return RunesToChars(runes[b:e])
- }
- return Chars{slice: chars.slice[b:e], inBytes: true}
-}
-
-func (chars *Chars) Split(delimiter string) []Chars {
- delim := []rune(delimiter)
- numChars := chars.Length()
- numDelim := len(delim)
- begin := 0
- ret := make([]Chars, 0, 1)
-
- for index := 0; index < numChars; {
- if index+numDelim <= numChars {
- match := true
- for off, d := range delim {
- if chars.Get(index+off) != d {
- match = false
- break
- }
- }
- // Found the delimiter
- if match {
- incr := Max(numDelim, 1)
- ret = append(ret, chars.Slice(begin, index+incr))
- index += incr
- begin = index
- continue
- }
- } else {
- // Impossible to find the delimiter in the remaining substring
- break
- }
- index++
- }
- if begin < numChars || len(ret) == 0 {
- ret = append(ret, chars.Slice(begin, numChars))
- }
- return ret
-}
diff --git a/src/util/chars_test.go b/src/util/chars_test.go
index 07b8dea5..b7983f30 100644
--- a/src/util/chars_test.go
+++ b/src/util/chars_test.go
@@ -44,29 +44,3 @@ func TestTrimLength(t *testing.T) {
check(" h o ", 5)
check(" ", 0)
}
-
-func TestSplit(t *testing.T) {
- check := func(str string, delim string, tokens ...string) {
- input := ToChars([]byte(str))
- result := input.Split(delim)
- if len(result) != len(tokens) {
- t.Errorf(
- "Invalid Split result for '%s': %d tokens found (expected %d): %s",
- str, len(result), len(tokens), result)
- }
- for idx, token := range tokens {
- if result[idx].ToString() != token {
- t.Errorf("Invalid Split result for '%s': %s (expected %s)",
- str, result[idx].ToString(), token)
- }
- }
- }
- check("abc:def::", ":", "abc:", "def:", ":")
- check("abc:def::", "-", "abc:def::")
- check("abc", "", "a", "b", "c")
- check("abc", "a", "a", "bc")
- check("abc", "ab", "ab", "c")
- check("abc", "abc", "abc")
- check("abc", "abcd", "abc")
- check("", "abcd", "")
-}