aboutsummaryrefslogtreecommitdiff
path: root/src/encoding
diff options
context:
space:
mode:
authorcuiweixie <cuiweixie@gmail.com>2022-09-28 00:29:30 +0800
committerGopher Robot <gobot@golang.org>2022-09-28 03:44:25 +0000
commit09919ac3396f1de63dd5556758ac2dd10ecb9b9f (patch)
tree468898e87e509d79f63ad9b8a0eb927f047506aa /src/encoding
parent9aa7107cb58417db4b19ea5f8773875a418270f3 (diff)
downloadgo-09919ac3396f1de63dd5556758ac2dd10ecb9b9f.tar.xz
encoding/xml: use bytes.Clone
Change-Id: I3218b1e3f8869f579facddb29471df13c835dc66 Reviewed-on: https://go-review.googlesource.com/c/go/+/435281 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Diffstat (limited to 'src/encoding')
-rw-r--r--src/encoding/xml/xml.go14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/encoding/xml/xml.go b/src/encoding/xml/xml.go
index 3459a8604f..50a91a897f 100644
--- a/src/encoding/xml/xml.go
+++ b/src/encoding/xml/xml.go
@@ -80,21 +80,15 @@ type EndElement struct {
// the characters they represent.
type CharData []byte
-func makeCopy(b []byte) []byte {
- b1 := make([]byte, len(b))
- copy(b1, b)
- return b1
-}
-
// Copy creates a new copy of CharData.
-func (c CharData) Copy() CharData { return CharData(makeCopy(c)) }
+func (c CharData) Copy() CharData { return CharData(bytes.Clone(c)) }
// A Comment represents an XML comment of the form <!--comment-->.
// The bytes do not include the <!-- and --> comment markers.
type Comment []byte
// Copy creates a new copy of Comment.
-func (c Comment) Copy() Comment { return Comment(makeCopy(c)) }
+func (c Comment) Copy() Comment { return Comment(bytes.Clone(c)) }
// A ProcInst represents an XML processing instruction of the form <?target inst?>
type ProcInst struct {
@@ -104,7 +98,7 @@ type ProcInst struct {
// Copy creates a new copy of ProcInst.
func (p ProcInst) Copy() ProcInst {
- p.Inst = makeCopy(p.Inst)
+ p.Inst = bytes.Clone(p.Inst)
return p
}
@@ -113,7 +107,7 @@ func (p ProcInst) Copy() ProcInst {
type Directive []byte
// Copy creates a new copy of Directive.
-func (d Directive) Copy() Directive { return Directive(makeCopy(d)) }
+func (d Directive) Copy() Directive { return Directive(bytes.Clone(d)) }
// CopyToken returns a copy of a Token.
func CopyToken(t Token) Token {