3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-14 16:09:32 +01:00

use maps.Clone from go1.21

This commit is contained in:
Shivaram Lingamneni 2023-08-15 20:57:52 -04:00
parent 28d9a7ff63
commit f77d430d25
5 changed files with 8 additions and 14 deletions

View File

@ -7,6 +7,7 @@ package irc
import (
"fmt"
"maps"
"strconv"
"strings"
"time"
@ -158,7 +159,7 @@ func (channel *Channel) ExportRegistration() (info RegisteredChannel) {
info.Bans = channel.lists[modes.BanMask].Masks()
info.Invites = channel.lists[modes.InviteMask].Masks()
info.Excepts = channel.lists[modes.ExceptMask].Masks()
info.AccountToUMode = utils.CopyMap(channel.accountToUMode)
info.AccountToUMode = maps.Clone(channel.accountToUMode)
info.Settings = channel.settings

View File

@ -8,6 +8,7 @@ package irc
import (
"crypto/x509"
"fmt"
"maps"
"net"
"runtime/debug"
"strconv"
@ -1743,7 +1744,7 @@ func (client *Client) handleRegisterTimeout() {
func (client *Client) copyLastSeen() (result map[string]time.Time) {
client.stateMutex.RLock()
defer client.stateMutex.RUnlock()
return utils.CopyMap(client.lastSeen)
return maps.Clone(client.lastSeen)
}
// these are bit flags indicating what part of the client status is "dirty"

View File

@ -4,9 +4,8 @@
package irc
import (
"maps"
"time"
"github.com/ergochat/ergo/irc/utils"
)
// fakelag is a system for artificially delaying commands when a user issues
@ -40,7 +39,7 @@ func (fl *Fakelag) Initialize(config FakelagConfig) {
fl.config = config
// XXX don't share mutable member CommandBudgets:
if config.CommandBudgets != nil {
fl.config.CommandBudgets = utils.CopyMap(config.CommandBudgets)
fl.config.CommandBudgets = maps.Clone(config.CommandBudgets)
}
fl.nowFunc = time.Now
fl.sleepFunc = time.Sleep

View File

@ -5,6 +5,7 @@ package irc
import (
"fmt"
"maps"
"net"
"time"
@ -515,7 +516,7 @@ func (client *Client) GetReadMarker(cfname string) (result string) {
func (client *Client) copyReadMarkers() (result map[string]time.Time) {
client.stateMutex.RLock()
defer client.stateMutex.RUnlock()
return utils.CopyMap(client.readMarkers)
return maps.Clone(client.readMarkers)
}
func (client *Client) SetReadMarker(cfname string, now time.Time) (result time.Time) {

View File

@ -27,11 +27,3 @@ func SetLiteral[T comparable](elems ...T) HashSet[T] {
}
return result
}
func CopyMap[K comparable, V any](input map[K]V) (result map[K]V) {
result = make(map[K]V, len(input))
for key, value := range input {
result[key] = value
}
return
}