Skip to content

Commit 54b74ee

Browse files
authored
Add with_capacity to BezPath (#418)
The reason I want this is that it makes convert `usvg` paths to kurbo `BezPath` more efficient.
1 parent 237b333 commit 54b74ee

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This release has an [MSRV][] of 1.65.
2121
- Implement `Sum` for `Vec2`. ([#399][] by [@Philipp-M][])
2222
- Add triangle shape. ([#350][] by [@juliapaci][])
2323
- Add `Vec2::turn_90` and `Vec2::rotate_scale` methods ([#409] by [@raphlinus][])
24+
- Add `BezPath::with_capacity` method ([#418] by [@LaurenzV][])
2425

2526
### Changed
2627

@@ -69,6 +70,7 @@ Note: A changelog was not kept for or before this release
6970
[@dominikh]: https://github.com/dominikh
7071
[@GabrielDertoni]: https://github.com/GabrielDertoni
7172
[@juliapaci]: https://github.com/juliapaci
73+
[@LaurenzV]: https://github.com/LaurenzV
7274
[@nils-mathieu]: https://github.com/nils-mathieu
7375
[@Philipp-M]: https://github.com/Philipp-M
7476
[@platlas]: https://github.com/platlas
@@ -101,6 +103,7 @@ Note: A changelog was not kept for or before this release
101103
[#390]: https://github.com/linebender/kurbo/pull/390
102104
[#399]: https://github.com/linebender/kurbo/pull/399
103105
[#409]: https://github.com/linebender/kurbo/pull/409
106+
[#418]: https://github.com/linebender/kurbo/pull/418
104107

105108
[Unreleased]: https://github.com/linebender/kurbo/compare/v0.11.1...HEAD
106109
[0.11.0]: https://github.com/linebender/kurbo/releases/tag/v0.11.0

src/bezpath.rs

+8
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ impl BezPath {
179179
Default::default()
180180
}
181181

182+
/// Create a new path with the specified capacity.
183+
///
184+
/// This can be useful if you already know how many path elements the path
185+
/// will consist of, to prevent reallocations.
186+
pub fn with_capacity(capacity: usize) -> BezPath {
187+
BezPath(Vec::with_capacity(capacity))
188+
}
189+
182190
/// Create a path from a vector of path elements.
183191
///
184192
/// `BezPath` also implements `FromIterator<PathEl>`, so it works with `collect`:

0 commit comments

Comments
 (0)