Changed slice code to use append()

This commit is contained in:
jim teeuwen 2010-11-05 01:26:35 +01:00
parent 18011ea2f0
commit 8c492695c1
2 changed files with 6 additions and 25 deletions

View File

@ -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
}

View File

@ -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