@@ -1893,20 +1893,20 @@ class Path extends NativeFieldWrapperClass2 {
18931893 Path () { _constructor (); }
18941894 void _constructor () native 'Path_constructor' ;
18951895
1896- // Workaround for tonic, which expects classes with native fields to have a
1897- // private constructor.
1898- // TODO(dnfield): rework this to use ClaimNativeField - https://github.com/flutter/flutter/issues/50997
1899- @pragma ('vm:entry-point' )
1900- Path ._() { _constructor (); }
1896+ /// Avoids creating a new native backing for the path for methods that will
1897+ /// create it later, such as [Path.from] , [shift] and [transform] .
1898+ Path ._();
19011899
19021900 /// Creates a copy of another [Path] .
19031901 ///
19041902 /// This copy is fast and does not require additional memory unless either
19051903 /// the `source` path or the path returned by this constructor are modified.
19061904 factory Path .from (Path source) {
1907- return source._clone ();
1905+ final Path clonedPath = Path ._();
1906+ source._clone (clonedPath);
1907+ return clonedPath;
19081908 }
1909- Path _clone () native 'Path_clone' ;
1909+ void _clone (Path outPath ) native 'Path_clone' ;
19101910
19111911 /// Determines how the interior of this path is calculated.
19121912 ///
@@ -2169,17 +2169,21 @@ class Path extends NativeFieldWrapperClass2 {
21692169 /// sub-path translated by the given offset.
21702170 Path shift (Offset offset) {
21712171 assert (_offsetIsValid (offset));
2172- return _shift (offset.dx, offset.dy);
2172+ final Path path = Path ._();
2173+ _shift (path, offset.dx, offset.dy);
2174+ return path;
21732175 }
2174- Path _shift (double dx, double dy) native 'Path_shift' ;
2176+ void _shift (Path outPath, double dx, double dy) native 'Path_shift' ;
21752177
21762178 /// Returns a copy of the path with all the segments of every
21772179 /// sub-path transformed by the given matrix.
21782180 Path transform (Float64List matrix4) {
21792181 assert (_matrix4IsValid (matrix4));
2180- return _transform (matrix4);
2182+ final Path path = Path ._();
2183+ _transform (path, matrix4);
2184+ return path;
21812185 }
2182- Path _transform (Float64List matrix4) native 'Path_transform' ;
2186+ void _transform (Path outPath, Float64List matrix4) native 'Path_transform' ;
21832187
21842188 /// Computes the bounding rectangle for this path.
21852189 ///
@@ -2455,9 +2459,11 @@ class _PathMeasure extends NativeFieldWrapperClass2 {
24552459
24562460 Path extractPath (int contourIndex, double start, double end, {bool startWithMoveTo = true }) {
24572461 assert (contourIndex <= currentContourIndex, 'Iterator must be advanced before index $contourIndex can be used.' );
2458- return _extractPath (contourIndex, start, end, startWithMoveTo: startWithMoveTo);
2462+ final Path path = Path ._();
2463+ _extractPath (path, contourIndex, start, end, startWithMoveTo: startWithMoveTo);
2464+ return path;
24592465 }
2460- Path _extractPath (int contourIndex, double start, double end, {bool startWithMoveTo = true }) native 'PathMeasure_getSegment' ;
2466+ void _extractPath (Path outPath, int contourIndex, double start, double end, {bool startWithMoveTo = true }) native 'PathMeasure_getSegment' ;
24612467
24622468 bool isClosed (int contourIndex) {
24632469 assert (contourIndex <= currentContourIndex, 'Iterator must be advanced before index $contourIndex can be used.' );
0 commit comments