| 1 |
// Copyright 2018 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package bytealg |
| 6 |
|
| 7 |
// Empirical data shows that using Index can get better |
| 8 |
// performance when len(s) <= 16. |
| 9 |
const MaxBruteForce = 16 |
| 10 |
|
| 11 |
func init() { |
| 12 |
// Optimize cases where the length of the substring is less than 32 bytes |
| 13 |
MaxLen = 32 |
| 14 |
} |
| 15 |
|
| 16 |
// Cutover reports the number of failures of IndexByte we should tolerate |
| 17 |
// before switching over to Index. |
| 18 |
// n is the number of bytes processed so far. |
| 19 |
// See the bytes.Index implementation for details. |
| 20 |
func Cutover(n int) int { |
| 21 |
// 1 error per 16 characters, plus a few slop to start. |
| 22 |
return 4 + n>>4 |
| 23 |
} |