Skip to content

Commit

Permalink
replace a strings.Split call with non-allocating code
Browse files Browse the repository at this point in the history
  • Loading branch information
ijt committed Jan 13, 2023
1 parent bc05410 commit 45b5c9c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions v2/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,16 @@ func parseDateWord(d *date, w string) (string, bool) {

// MMM-DD
if strings.Count(w, "-") == 1 {
dashParts := strings.Split(w, "-")
if len(dashParts) == 2 {
m, ok := monthNameToMonth[dashParts[0]]
if ok {
dom, ok := parseDayOfMonthNoCheck(dashParts[1])
if ok && okDayOfMonth(dom) {
d.month = m
d.dayOfMonth = dom
return "md", true
}
idash := strings.IndexByte(w, '-')
mstr := w[:idash]
domstr := w[idash+1:]
m, ok := monthNameToMonth[mstr]
if ok {
dom, ok := parseDayOfMonthNoCheck(domstr)
if ok && okDayOfMonth(dom) {
d.month = m
d.dayOfMonth = dom
return "md", true
}
}
}
Expand Down

0 comments on commit 45b5c9c

Please sign in to comment.