mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-20 11:55:18 +00:00
4c3cd4c9e3
Because it's literally ten times faster: benchmark old ns/op new ns/op delta BenchmarkMatch-8 13842 1200 -91.33% BenchmarkMatchCached-8 139 147 +5.76% benchmark old allocs new allocs delta BenchmarkMatch-8 0 0 +0.00% BenchmarkMatchCached-8 0 0 +0.00% benchmark old bytes new bytes delta BenchmarkMatch-8 12 0 -100.00% BenchmarkMatchCached-8 0 0 +0.00%
44 lines
721 B
Go
44 lines
721 B
Go
package match
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gobwas/glob/runes"
|
|
"unicode/utf8"
|
|
)
|
|
|
|
// single represents ?
|
|
type Single struct {
|
|
Separators []rune
|
|
}
|
|
|
|
func NewSingle(s []rune) Single {
|
|
return Single{s}
|
|
}
|
|
|
|
func (self Single) Match(s string) bool {
|
|
r, w := utf8.DecodeRuneInString(s)
|
|
if len(s) > w {
|
|
return false
|
|
}
|
|
|
|
return runes.IndexRune(self.Separators, r) == -1
|
|
}
|
|
|
|
func (self Single) Len() int {
|
|
return lenOne
|
|
}
|
|
|
|
func (self Single) Index(s string) (int, []int) {
|
|
for i, r := range s {
|
|
if runes.IndexRune(self.Separators, r) == -1 {
|
|
return i, segmentsByRuneLength[utf8.RuneLen(r)]
|
|
}
|
|
}
|
|
|
|
return -1, nil
|
|
}
|
|
|
|
func (self Single) String() string {
|
|
return fmt.Sprintf("<single:![%s]>", string(self.Separators))
|
|
}
|