]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/xml: remove unnecessary memory allocation in Unmarshal
authorDmitry Vyukov <dvyukov@google.com>
Wed, 14 Jan 2015 18:32:05 +0000 (21:32 +0300)
committerDmitry Vyukov <dvyukov@google.com>
Thu, 15 Jan 2015 08:45:15 +0000 (08:45 +0000)
benchmark              old ns/op     new ns/op     delta
BenchmarkUnmarshal     75256         72626         -3.49%

benchmark              old allocs     new allocs     delta
BenchmarkUnmarshal     259            219            -15.44%

Change-Id: I7fd30739b045e35b95e6ef6a8ef2f15b0dd6839c
Reviewed-on: https://go-review.googlesource.com/2758
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/encoding/xml/marshal_test.go
src/encoding/xml/xml.go

index 14f73a75d5fbd8f381461537b45177102d36b724..cdd52ff97fb45981ca2412df44a6d1de043dc77b 100644 (file)
@@ -1148,12 +1148,14 @@ func TestMarshalFlush(t *testing.T) {
 }
 
 func BenchmarkMarshal(b *testing.B) {
+       b.ReportAllocs()
        for i := 0; i < b.N; i++ {
                Marshal(atomValue)
        }
 }
 
 func BenchmarkUnmarshal(b *testing.B) {
+       b.ReportAllocs()
        xml := []byte(atomXml)
        for i := 0; i < b.N; i++ {
                Unmarshal(xml, &Feed{})
index 8c15b98c3a9efacf82f7e9de32f4770a913c5cc4..5690b20256d2ea8731c1063a0ec9ea18f66ca22a 100644 (file)
@@ -1119,12 +1119,12 @@ func (d *Decoder) name() (s string, ok bool) {
        }
 
        // Now we check the characters.
-       s = d.buf.String()
-       if !isName([]byte(s)) {
-               d.err = d.syntaxError("invalid XML name: " + s)
+       b := d.buf.Bytes()
+       if !isName(b) {
+               d.err = d.syntaxError("invalid XML name: " + string(b))
                return "", false
        }
-       return s, true
+       return string(b), true
 }
 
 // Read a name and append its bytes to d.buf.