Skip to content

Commit

Permalink
Small speedup by pre-allocating some slices.
Browse files Browse the repository at this point in the history
  • Loading branch information
aligator committed Feb 9, 2021
1 parent 1a76a2d commit 88552fc
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions clip/clip.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ func clipperPoint(p data.MicroPoint) *clipper.IntPoint {
// clipperPaths converts the GoSlice Paths representation
// to the representation which is used by the external clipper lib.
func clipperPaths(p data.Paths) clipper.Paths {
var result clipper.Paths
for _, path := range p {
result = append(result, clipperPath(path))
result := make(clipper.Paths, len(p))
for i, path := range p {
result[i] = clipperPath(path)
}

return result
Expand All @@ -158,9 +158,9 @@ func clipperPaths(p data.Paths) clipper.Paths {
// clipperPath converts the GoSlice Path representation
// to the representation which is used by the external clipper lib.
func clipperPath(p data.Path) clipper.Path {
var result clipper.Path
for _, point := range p {
result = append(result, clipperPoint(point))
result := make(clipper.Path, len(p))
for i, point := range p {
result[i] = clipperPoint(point)
}

return result
Expand All @@ -177,9 +177,9 @@ func microPoint(p *clipper.IntPoint) data.MicroPoint {
// The parameter simplify enables simplifying of the path using
// the default simplification settings.
func microPath(p clipper.Path, simplify bool) data.Path {
var result data.Path
for _, point := range p {
result = append(result, microPoint(point))
result := make(data.Path, len(p))
for i, point := range p {
result[i] = microPoint(point)
}

if simplify {
Expand All @@ -193,9 +193,9 @@ func microPath(p clipper.Path, simplify bool) data.Path {
// The parameter simplify enables simplifying of the paths using
// the default simplification settings.
func microPaths(p clipper.Paths, simplify bool) data.Paths {
var result data.Paths
for _, path := range p {
result = append(result, microPath(path, simplify))
result := make(data.Paths, len(p))
for i, path := range p {
result[i] = microPath(path, simplify)
}
return result
}
Expand Down

0 comments on commit 88552fc

Please sign in to comment.