Skip to content

Commit fc37d5a

Browse files
committed
Use copy to inject the new elements
1 parent 82bf6e6 commit fc37d5a

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

disco/baller.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,10 @@ func (b *Baller) discoBallTopLevelSection(dc *discoContext, top *asciidoc.Sectio
151151
ae := asciidoc.NewAttributeEntry("xrefstyle")
152152
ae.Elements = asciidoc.Elements{asciidoc.NewString("basic")}
153153
if topIndex != -1 {
154-
newElements := make(asciidoc.Elements, 0, len(dc.doc.Elements)+2)
155-
newElements = append(newElements, dc.doc.Elements[:topIndex]...)
156-
newElements = append(newElements, ae, &asciidoc.NewLine{})
157-
newElements = append(newElements, dc.doc.Elements[topIndex:]...)
158-
dc.doc.Elements = newElements
154+
dc.doc.Elements = append(dc.doc.Elements, nil, nil)
155+
copy(dc.doc.Elements[topIndex+2:], dc.doc.Elements[topIndex:])
156+
dc.doc.Elements[topIndex] = ae
157+
dc.doc.Elements[topIndex+1] = &asciidoc.NewLine{}
159158
} else {
160159
dc.doc.Elements = append(asciidoc.Elements{ae, &asciidoc.NewLine{}}, dc.doc.Elements...)
161160
}

0 commit comments

Comments
 (0)