Skip to content

Commit

Permalink
use maps.Clone from go1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
slingamn committed Aug 16, 2023
1 parent 28d9a7f commit f77d430
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 14 deletions.
3 changes: 2 additions & 1 deletion irc/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package irc

import (
"fmt"
"maps"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion irc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package irc
import (
"crypto/x509"
"fmt"
"maps"
"net"
"runtime/debug"
"strconv"
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 2 additions & 3 deletions irc/fakelag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion irc/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package irc

import (
"fmt"
"maps"
"net"
"time"

Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 0 additions & 8 deletions irc/utils/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit f77d430

Please sign in to comment.