1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-27 06:16:09 -04:00

optimize map usage

This commit is contained in:
Darien Raymond 2018-05-31 12:05:25 +02:00
parent adade2bffd
commit 4a46817cf6
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 6 additions and 6 deletions

View File

@ -164,18 +164,14 @@ func (m *CachableDomainMatcher) ApplyDomain(domain string) bool {
now := time.Now()
if len(m.cache) > 256 && now.Sub(m.lastScan)/time.Second > 5 {
remove := make([]string, 0, 128)
now := time.Now()
for k, v := range m.cache {
if now.Sub(v.timestamp)/time.Second > 60 {
remove = append(remove, k)
delete(m.cache, k)
}
}
for _, v := range remove {
delete(m.cache, v)
}
m.lastScan = now
}

View File

@ -75,6 +75,10 @@ func (h *SessionHistory) removeExpiredEntries() {
h.Lock()
defer h.Unlock()
if len(h.cache) == 0 {
return
}
for session, expire := range h.cache {
if expire.Before(now) {
delete(h.cache, session)