mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 18:41:59 -07: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%
36 lines
530 B
Go
36 lines
530 B
Go
package match
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
type Suffix struct {
|
|
Suffix string
|
|
}
|
|
|
|
func NewSuffix(s string) Suffix {
|
|
return Suffix{s}
|
|
}
|
|
|
|
func (self Suffix) Len() int {
|
|
return lenNo
|
|
}
|
|
|
|
func (self Suffix) Match(s string) bool {
|
|
return strings.HasSuffix(s, self.Suffix)
|
|
}
|
|
|
|
func (self Suffix) Index(s string) (int, []int) {
|
|
idx := strings.Index(s, self.Suffix)
|
|
if idx == -1 {
|
|
return -1, nil
|
|
}
|
|
|
|
return 0, []int{idx + len(self.Suffix)}
|
|
}
|
|
|
|
func (self Suffix) String() string {
|
|
return fmt.Sprintf("<suffix:%s>", self.Suffix)
|
|
}
|