mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-27 19:56:22 -05:00
don't alloc new maps until required
This commit is contained in:
parent
4e30ac33d0
commit
e6b5356ea9
@ -19,18 +19,19 @@ type DomainMatcherGroup struct {
|
|||||||
|
|
||||||
func (g *DomainMatcherGroup) Add(domain string, value uint32) {
|
func (g *DomainMatcherGroup) Add(domain string, value uint32) {
|
||||||
if g.root == nil {
|
if g.root == nil {
|
||||||
g.root = &node{
|
g.root = new(node)
|
||||||
sub: make(map[string]*node),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
current := g.root
|
current := g.root
|
||||||
parts := breakDomain(domain)
|
parts := breakDomain(domain)
|
||||||
for i := len(parts) - 1; i >= 0; i-- {
|
for i := len(parts) - 1; i >= 0; i-- {
|
||||||
part := parts[i]
|
part := parts[i]
|
||||||
|
if current.sub == nil {
|
||||||
|
current.sub = make(map[string]*node)
|
||||||
|
}
|
||||||
next := current.sub[part]
|
next := current.sub[part]
|
||||||
if next == nil {
|
if next == nil {
|
||||||
next = &node{sub: make(map[string]*node)}
|
next = new(node)
|
||||||
current.sub[part] = next
|
current.sub[part] = next
|
||||||
}
|
}
|
||||||
current = next
|
current = next
|
||||||
@ -52,6 +53,9 @@ func (g *DomainMatcherGroup) Match(domain string) uint32 {
|
|||||||
parts := breakDomain(domain)
|
parts := breakDomain(domain)
|
||||||
for i := len(parts) - 1; i >= 0; i-- {
|
for i := len(parts) - 1; i >= 0; i-- {
|
||||||
part := parts[i]
|
part := parts[i]
|
||||||
|
if current.sub == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
next := current.sub[part]
|
next := current.sub[part]
|
||||||
if next == nil {
|
if next == nil {
|
||||||
break
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user