1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-07 02:36:26 -05:00

don't alloc new maps until required

This commit is contained in:
Darien Raymond 2018-08-22 22:49:02 +02:00
parent 4e30ac33d0
commit e6b5356ea9
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -19,18 +19,19 @@ type DomainMatcherGroup struct {
func (g *DomainMatcherGroup) Add(domain string, value uint32) {
if g.root == nil {
g.root = &node{
sub: make(map[string]*node),
}
g.root = new(node)
}
current := g.root
parts := breakDomain(domain)
for i := len(parts) - 1; i >= 0; i-- {
part := parts[i]
if current.sub == nil {
current.sub = make(map[string]*node)
}
next := current.sub[part]
if next == nil {
next = &node{sub: make(map[string]*node)}
next = new(node)
current.sub[part] = next
}
current = next
@ -52,6 +53,9 @@ func (g *DomainMatcherGroup) Match(domain string) uint32 {
parts := breakDomain(domain)
for i := len(parts) - 1; i >= 0; i-- {
part := parts[i]
if current.sub == nil {
break
}
next := current.sub[part]
if next == nil {
break