2
0

Small performance boost

This commit is contained in:
Miloš Mileusnić
2023-04-14 12:12:35 +02:00
parent b13e69df71
commit 8d5141dfc7
+12 -10
View File
@@ -31,15 +31,6 @@ type UserAgent struct {
Bot bool
}
// TODO: turn to slice, check performance
var ignore = map[string]struct{}{
"KHTML, like Gecko": {},
"U": {},
"compatible": {},
"Mozilla": {},
"WOW64": {},
}
// Constants for browsers and operating systems for easier comparison
const (
Windows = "Windows"
@@ -372,7 +363,8 @@ func parse(userAgent string) properties {
addToken := func() {
if buff.Len() != 0 {
s := strings.TrimSpace(buff.String())
if _, ign := ignore[s]; !ign {
if !ignore(s) {
// if _, ign := ignore[s]; !ign {
if isURL {
s = strings.TrimPrefix(s, "+")
}
@@ -468,6 +460,16 @@ func checkVer(s string) (name, v string) {
// return s[:i], s[i+1:]
}
// ignore retursn true if token should be ignored
func ignore(s string) bool {
switch s {
case "KHTML, like Gecko", "U", "compatible", "Mozilla", "WOW64":
return true
default:
return false
}
}
type property struct {
Key string
Value string