]> Cypherpunks repositories - gostls13.git/commitdiff
undo CL 13004046 / 5db14b33d6ef
authorRob Pike <r@golang.org>
Thu, 5 Sep 2013 21:54:43 +0000 (07:54 +1000)
committerAndrew Gerrand <adg@golang.org>
Thu, 5 Sep 2013 21:54:43 +0000 (07:54 +1000)
Flushing after every token negates the point of buffering. A different approach is required.

««« original CL description
encoding/xml: flush buffer after encoding token

R=rsc, bradfitz, adg
CC=golang-dev
https://golang.org/cl/13004046

»»»

R=golang-dev, adg, rsc
CC=golang-dev
https://golang.org/cl/13515043

src/pkg/encoding/xml/marshal.go
src/pkg/encoding/xml/marshal_test.go

index 06bdec4f739c9dc4caf4920d756a7b7829f5a149..a6ee5d51285b729ec307f8fc7e927e5f666b3175 100644 (file)
@@ -196,6 +196,7 @@ func (enc *Encoder) EncodeToken(t Token) error {
                p.WriteString("<!--")
                p.Write(t)
                p.WriteString("-->")
+               return p.cachedWriteError()
        case ProcInst:
                if t.Target == "xml" || !isNameString(t.Target) {
                        return fmt.Errorf("xml: EncodeToken of ProcInst with invalid Target")
@@ -218,7 +219,7 @@ func (enc *Encoder) EncodeToken(t Token) error {
                p.Write(t)
                p.WriteString(">")
        }
-       return p.Flush()
+       return p.cachedWriteError()
 }
 
 type printer struct {
index 31d4d4d853fe1d09370aef46f3f984b8aa920ca5..8d9239eb4adcf92e9c45c611346f90f02c983788 100644 (file)
@@ -1076,15 +1076,6 @@ func TestMarshalWriteIOErrors(t *testing.T) {
        }
 }
 
-func TestEncodeTokenFlush(t *testing.T) {
-       var buf bytes.Buffer
-       enc := NewEncoder(&buf)
-       enc.EncodeToken(StartElement{Name: Name{Local: "some-tag"}})
-       if g, w := buf.String(), "<some-tag>"; g != w {
-               t.Errorf("Encoder wrote %q, want %q", g, w)
-       }
-}
-
 func BenchmarkMarshal(b *testing.B) {
        for i := 0; i < b.N; i++ {
                Marshal(atomValue)