diff --git a/xmlx/document.go b/xmlx/document.go index 55d7edf..86c26e1 100644 --- a/xmlx/document.go +++ b/xmlx/document.go @@ -183,20 +183,17 @@ func (this *Document) LoadUri(uri string) (err os.Error) { } func (this *Document) LoadStream(r io.Reader) (err os.Error) { - var data []byte - - t := bytes.NewBuffer(data) + var buf bytes.Buffer s := make([]byte, 1024) for { - _, err := r.Read(s) - if err != nil { + if _, err = r.Read(s); err != nil { break } - t.Write(s) + buf.Write(s) } - err = this.LoadString(t.String()) + err = this.LoadString(buf.String()) return } diff --git a/xmlx/node.go b/xmlx/node.go index e6ec31f..bed3dca 100644 --- a/xmlx/node.go +++ b/xmlx/node.go @@ -249,14 +249,7 @@ func (this *Node) SelectNodes(namespace, name string) []*Node { func rec_SelectNodes(cn *Node, namespace, name string, list *[]*Node) { if cn.Name.Space == namespace && cn.Name.Local == name { - l := len(*list) - if l >= cap(*list) { - c := make([]*Node, l, l+16) - copy(c, *list) - *list = c - } - *list = (*list)[0 : l+1] - (*list)[l] = cn + *list = append(*list, cn) return } @@ -361,16 +354,7 @@ func (this *Node) AddChild(t *Node) { t.Parent.RemoveChild(t) } t.Parent = this - - l := len(this.Children) - if l >= cap(this.Children) { - c := make([]*Node, l, l+10) - copy(c, this.Children) - this.Children = c - } - - this.Children = this.Children[0 : l+1] - this.Children[l] = t + this.Children = append(this.Children, t) } // Remove a child node