Sfoglia il codice sorgente

use strings.Builder instead of bytes.Buffer where applicable

tags/v2.2.0-rc1
Shivaram Lingamneni 4 anni fa
parent
commit
00e2c2816b
3 ha cambiato i file con 6 aggiunte e 8 eliminazioni
  1. 1
    2
      irc/channel.go
  2. 4
    4
      irc/utils/glob.go
  3. 1
    2
      irc/utils/text.go

+ 1
- 2
irc/channel.go Vedi File

6
 package irc
6
 package irc
7
 
7
 
8
 import (
8
 import (
9
-	"bytes"
10
 	"fmt"
9
 	"fmt"
11
 	"strconv"
10
 	"strconv"
12
 	"strings"
11
 	"strings"
447
 
446
 
448
 	maxNamLen := 480 - len(client.server.name) - len(client.Nick())
447
 	maxNamLen := 480 - len(client.server.name) - len(client.Nick())
449
 	var namesLines []string
448
 	var namesLines []string
450
-	var buffer bytes.Buffer
449
+	var buffer strings.Builder
451
 	if isJoined || !channel.flags.HasMode(modes.Secret) || isOper {
450
 	if isJoined || !channel.flags.HasMode(modes.Secret) || isOper {
452
 		for _, target := range channel.Members() {
451
 		for _, target := range channel.Members() {
453
 			var nick string
452
 			var nick string

+ 4
- 4
irc/utils/glob.go Vedi File

4
 package utils
4
 package utils
5
 
5
 
6
 import (
6
 import (
7
-	"bytes"
8
 	"regexp"
7
 	"regexp"
9
 	"regexp/syntax"
8
 	"regexp/syntax"
9
+	"strings"
10
 )
10
 )
11
 
11
 
12
 // yet another glob implementation in Go
12
 // yet another glob implementation in Go
13
 
13
 
14
-func addRegexp(buf *bytes.Buffer, glob string, submatch bool) (err error) {
14
+func addRegexp(buf *strings.Builder, glob string, submatch bool) (err error) {
15
 	for _, r := range glob {
15
 	for _, r := range glob {
16
 		switch r {
16
 		switch r {
17
 		case '*':
17
 		case '*':
36
 }
36
 }
37
 
37
 
38
 func CompileGlob(glob string, submatch bool) (result *regexp.Regexp, err error) {
38
 func CompileGlob(glob string, submatch bool) (result *regexp.Regexp, err error) {
39
-	var buf bytes.Buffer
39
+	var buf strings.Builder
40
 	buf.WriteByte('^')
40
 	buf.WriteByte('^')
41
 	err = addRegexp(&buf, glob, submatch)
41
 	err = addRegexp(&buf, glob, submatch)
42
 	if err != nil {
42
 	if err != nil {
50
 // This is used for channel ban/invite/exception lists. It's applicable to k-lines
50
 // This is used for channel ban/invite/exception lists. It's applicable to k-lines
51
 // but we're not using it there yet.
51
 // but we're not using it there yet.
52
 func CompileMasks(masks []string) (result *regexp.Regexp, err error) {
52
 func CompileMasks(masks []string) (result *regexp.Regexp, err error) {
53
-	var buf bytes.Buffer
53
+	var buf strings.Builder
54
 	buf.WriteString("^(")
54
 	buf.WriteString("^(")
55
 	for i, mask := range masks {
55
 	for i, mask := range masks {
56
 		err = addRegexp(&buf, mask, false)
56
 		err = addRegexp(&buf, mask, false)

+ 1
- 2
irc/utils/text.go Vedi File

4
 package utils
4
 package utils
5
 
5
 
6
 import (
6
 import (
7
-	"bytes"
8
 	"strings"
7
 	"strings"
9
 	"time"
8
 	"time"
10
 )
9
 )
98
 type TokenLineBuilder struct {
97
 type TokenLineBuilder struct {
99
 	lineLen int
98
 	lineLen int
100
 	delim   string
99
 	delim   string
101
-	buf     bytes.Buffer
100
+	buf     strings.Builder
102
 	result  []string
101
 	result  []string
103
 }
102
 }
104
 
103
 

Loading…
Annulla
Salva