Skip to content

Commit

Permalink
remove regex compile from hot path
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Mar 31, 2020
1 parent a0cad9d commit be4a5f6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion extracts_v6.go
Original file line number Diff line number Diff line change
Expand Up @@ -1952,6 +1952,7 @@ func extractUniverseSpeedV6(pageHTML []byte) int64 {

var planetInfosRgx = regexp.MustCompile(`([^\[]+) \[(\d+):(\d+):(\d+)]([\d.,]+)(?i)(?:km|км|公里|χμ) \((\d+)/(\d+)\)(?:de|da|od|mellem|от)?\s*([-\d]+).+C\s*(?:bis|para|to|à|至|a|~|do|ile|tot|og|до|až|til|la|έως)\s*([-\d]+).+C`)
var moonInfosRgx = regexp.MustCompile(`([^\[]+) \[(\d+):(\d+):(\d+)]([\d.]+)(?i)(?:km|км|χμ) \((\d+)/(\d+)\)`)
var cpRgx = regexp.MustCompile(`&cp=(\d+)`)

func extractPlanetFromSelectionV6(s *goquery.Selection, b *OGame) (Planet, error) {
el, _ := s.Attr("id")
Expand Down Expand Up @@ -2006,7 +2007,7 @@ func extractMoonFromSelectionV6(moonLink *goquery.Selection, b *OGame) (Moon, er
if !found {
return Moon{}, errors.New("no moon found")
}
m := regexp.MustCompile(`&cp=(\d+)`).FindStringSubmatch(href)
m := cpRgx.FindStringSubmatch(href)
id, _ := strconv.ParseInt(m[1], 10, 64)
title, _ := moonLink.Attr("title")
root, err := html.Parse(strings.NewReader(title))
Expand Down

0 comments on commit be4a5f6

Please sign in to comment.