Browse Source

use maps.Clone from go1.21

tags/v2.12.0-rc1
Shivaram Lingamneni 8 months ago
parent
commit
f77d430d25
5 changed files with 8 additions and 14 deletions
  1. 2
    1
      irc/channel.go
  2. 2
    1
      irc/client.go
  3. 2
    3
      irc/fakelag.go
  4. 2
    1
      irc/getters.go
  5. 0
    8
      irc/utils/types.go

+ 2
- 1
irc/channel.go View File

@@ -7,6 +7,7 @@ package irc
7 7
 
8 8
 import (
9 9
 	"fmt"
10
+	"maps"
10 11
 	"strconv"
11 12
 	"strings"
12 13
 	"time"
@@ -158,7 +159,7 @@ func (channel *Channel) ExportRegistration() (info RegisteredChannel) {
158 159
 	info.Bans = channel.lists[modes.BanMask].Masks()
159 160
 	info.Invites = channel.lists[modes.InviteMask].Masks()
160 161
 	info.Excepts = channel.lists[modes.ExceptMask].Masks()
161
-	info.AccountToUMode = utils.CopyMap(channel.accountToUMode)
162
+	info.AccountToUMode = maps.Clone(channel.accountToUMode)
162 163
 
163 164
 	info.Settings = channel.settings
164 165
 

+ 2
- 1
irc/client.go View File

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

+ 2
- 3
irc/fakelag.go View File

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

+ 2
- 1
irc/getters.go View File

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

+ 0
- 8
irc/utils/types.go View File

@@ -27,11 +27,3 @@ func SetLiteral[T comparable](elems ...T) HashSet[T] {
27 27
 	}
28 28
 	return result
29 29
 }
30
-
31
-func CopyMap[K comparable, V any](input map[K]V) (result map[K]V) {
32
-	result = make(map[K]V, len(input))
33
-	for key, value := range input {
34
-		result[key] = value
35
-	}
36
-	return
37
-}

Loading…
Cancel
Save