Changed slice code to use append()
This commit is contained in:
parent
18011ea2f0
commit
8c492695c1
|
@ -183,20 +183,17 @@ func (this *Document) LoadUri(uri string) (err os.Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Document) LoadStream(r io.Reader) (err os.Error) {
|
func (this *Document) LoadStream(r io.Reader) (err os.Error) {
|
||||||
var data []byte
|
var buf bytes.Buffer
|
||||||
|
|
||||||
t := bytes.NewBuffer(data)
|
|
||||||
s := make([]byte, 1024)
|
s := make([]byte, 1024)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
_, err := r.Read(s)
|
if _, err = r.Read(s); err != nil {
|
||||||
if err != nil {
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
t.Write(s)
|
buf.Write(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = this.LoadString(t.String())
|
err = this.LoadString(buf.String())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
20
xmlx/node.go
20
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) {
|
func rec_SelectNodes(cn *Node, namespace, name string, list *[]*Node) {
|
||||||
if cn.Name.Space == namespace && cn.Name.Local == name {
|
if cn.Name.Space == namespace && cn.Name.Local == name {
|
||||||
l := len(*list)
|
*list = append(*list, cn)
|
||||||
if l >= cap(*list) {
|
|
||||||
c := make([]*Node, l, l+16)
|
|
||||||
copy(c, *list)
|
|
||||||
*list = c
|
|
||||||
}
|
|
||||||
*list = (*list)[0 : l+1]
|
|
||||||
(*list)[l] = cn
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,16 +354,7 @@ func (this *Node) AddChild(t *Node) {
|
||||||
t.Parent.RemoveChild(t)
|
t.Parent.RemoveChild(t)
|
||||||
}
|
}
|
||||||
t.Parent = this
|
t.Parent = this
|
||||||
|
this.Children = append(this.Children, t)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove a child node
|
// Remove a child node
|
||||||
|
|
Loading…
Reference in New Issue