Skip to content

Commit

Permalink
Merge pull request muety#565 from Juneezee/perf/regexp-matchstring
Browse files Browse the repository at this point in the history
perf: avoid allocations with `(*regexp.Regexp).MatchString`
  • Loading branch information
muety authored Nov 24, 2023
2 parents c714085 + cbdf341 commit 8449348
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion models/mail_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (m MailAddress) Domain() string {
}

func (m MailAddress) Valid() bool {
return emailAddrRegex.Match([]byte(m))
return emailAddrRegex.MatchString(string(m))
}

func (m MailAddresses) Strings() []string {
Expand Down
2 changes: 1 addition & 1 deletion models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func ValidatePassword(password string) bool {

// ValidateEmail checks that, if an email address is given, it has proper syntax and (if not in dev mode) an MX record exists for the domain
func ValidateEmail(email string) bool {
return email == "" || (mailRegex.Match([]byte(email)) && (conf.Get().IsDev() || utils.CheckEmailMX(email)))
return email == "" || (mailRegex.MatchString(email) && (conf.Get().IsDev() || utils.CheckEmailMX(email)))
}

func ValidateTimezone(tz string) bool {
Expand Down
2 changes: 1 addition & 1 deletion scripts/email_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func CheckEmailMX(email string) bool {
}

func ValidateEmail(email string) bool {
return mailRegex.Match([]byte(email)) && CheckEmailMX(email)
return mailRegex.MatchString(email) && CheckEmailMX(email)
}

func main() {
Expand Down

0 comments on commit 8449348

Please sign in to comment.