]> Sergey Matveev's repositories - btrtrc.git/commitdiff
iplist: Reuse the p2p line regexp
authorMatt Joiner <anacrolix@gmail.com>
Tue, 2 Dec 2014 05:49:21 +0000 (23:49 -0600)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 2 Dec 2014 05:49:21 +0000 (23:49 -0600)
iplist/iplist.go

index 4827f871949123ce3f9e2ec3cf33dfe3770da54a..5467c33055f177011307172e413526ebbf67c10d 100644 (file)
@@ -50,6 +50,8 @@ func (me *IPList) Lookup(ip net.IP) (r *Range) {
        return
 }
 
+var p2pBlocklistLineRe = regexp.MustCompile(`(.*):([\d.]+)-([\d.]+)`)
+
 // Parse a line of the PeerGuardian Text Lists (P2P) Format. Returns !ok but
 // no error if a line doesn't contain a range but isn't erroneous, such as
 // comment and blank lines.
@@ -58,7 +60,7 @@ func ParseBlocklistP2PLine(l string) (r Range, ok bool, err error) {
        if l == "" || strings.HasPrefix(l, "#") {
                return
        }
-       sms := regexp.MustCompile(`(.*):([\d.]+)-([\d.]+)`).FindStringSubmatch(l)
+       sms := p2pBlocklistLineRe.FindStringSubmatch(l)
        if sms == nil {
                err = fmt.Errorf("error parsing %q", l)
                return