Skip to content

Commit 3769c2b

Browse files
authored
Merge pull request #26 from alexey-slivkin/patch-1
Removed regexp recompilation for each helper run
2 parents 9dd1f5c + b4c25de commit 3769c2b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

helper.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import (
77
"unicode"
88
)
99

10+
var selectCapitalRegexp = regexp.MustCompile(SelectCapital)
11+
1012
func caseHelper(input string, isCamel bool, rule ...string) []string {
1113
if !isCamel {
12-
re := regexp.MustCompile(SelectCapital)
13-
input = re.ReplaceAllString(input, ReplaceCapital)
14+
input = selectCapitalRegexp.ReplaceAllString(input, ReplaceCapital)
1415
}
1516
input = strings.Join(strings.Fields(strings.TrimSpace(input)), " ")
1617
if len(rule) > 0 && len(rule)%2 != 0 {

stringy.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"unicode"
1111
)
1212

13+
var matchWordRegexp = regexp.MustCompile(`[\s]*[\W]\pN`)
14+
1315
// input is struct that holds input from user and result
1416
type input struct {
1517
Input string
@@ -228,9 +230,8 @@ func (i *input) LcFirst() string {
228230

229231
// Lines returns slice of strings by removing white space characters
230232
func (i *input) Lines() []string {
231-
input := getInput(*i)
232-
matchWord := regexp.MustCompile(`[\s]*[\W]\pN`)
233-
result := matchWord.ReplaceAllString(input, " ")
233+
input := getInput(*i)
234+
result := matchWordRegexp.ReplaceAllString(input, " ")
234235
return strings.Fields(strings.TrimSpace(result))
235236
}
236237

0 commit comments

Comments
 (0)