1111#include < yoga/node/Node.h>
1212#include < vector>
1313#include < yoga/style/GridLine.h>
14- #include < map >
14+ #include < unordered_map >
1515#include < unordered_set>
1616
1717namespace facebook ::yoga {
@@ -155,7 +155,7 @@ struct AutoPlacement {
155155 // Step 1: Position anything that's not auto-positioned.
156156 // In spec level 1, span is always definite. Default is 1.
157157 // So for grid position to be definite, we need either start or end to be definite.
158- for (auto child: node->getChildren ()) {
158+ for (const auto & child: node->getChildren ()) {
159159 if (child->style ().positionType () == PositionType::Absolute) {
160160 continue ;
161161 }
@@ -194,8 +194,8 @@ struct AutoPlacement {
194194
195195 // Step 2: Process the items locked to a given row.
196196 // Definite row positions only, exclude items with definite column positions.
197- std::map <int32_t , int32_t > rowStartToColumnStartCache;
198- for (auto child: node->getChildren ()) {
197+ std::unordered_map <int32_t , int32_t > rowStartToColumnStartCache;
198+ for (const auto & child: node->getChildren ()) {
199199 if (child->style ().positionType () == PositionType::Absolute) {
200200 continue ;
201201 }
@@ -215,9 +215,8 @@ struct AutoPlacement {
215215 auto rowStart = rowPlacement.start ;
216216 auto rowEnd = rowPlacement.end ;
217217
218- auto columnStart = rowStartToColumnStartCache.find (rowStart) ==
219- rowStartToColumnStartCache.end () ?
220- minColumnStart : rowStartToColumnStartCache[rowStart];
218+ auto columnStart = rowStartToColumnStartCache.contains (rowStart) ?
219+ rowStartToColumnStartCache[rowStart] : minColumnStart;
221220
222221 auto columnPlacement = GridItemTrackPlacement::resolveLinePlacement (gridItemColumnStart, gridItemColumnEnd, explicitColumnLineCount);
223222 auto columnSpan = columnPlacement.span ;
@@ -234,7 +233,7 @@ struct AutoPlacement {
234233 child
235234 };
236235
237- for (auto placedItem: gridItemAreas) {
236+ for (const auto & placedItem: gridItemAreas) {
238237 if (gridItemArea.overlaps (placedItem)) {
239238 columnStart++;
240239 columnEnd = columnStart + columnSpan;
@@ -255,7 +254,7 @@ struct AutoPlacement {
255254 // Step 3: Determine the columns in the implicit grid.
256255 // TODO: we dont need this loop. we can do it in above steps. But keeping it for now, to match the spec.
257256 auto largestColumnSpan = 1 ;
258- for (auto child: node->getChildren ()) {
257+ for (const auto & child: node->getChildren ()) {
259258 if (child->style ().positionType () == PositionType::Absolute) {
260259 continue ;
261260 }
@@ -291,7 +290,7 @@ struct AutoPlacement {
291290 minColumnStart,
292291 minRowStart
293292 };
294- for (auto child: node->getChildren ()) {
293+ for (const auto & child: node->getChildren ()) {
295294 if (child->style ().positionType () == PositionType::Absolute) {
296295 continue ;
297296 }
@@ -342,7 +341,7 @@ struct AutoPlacement {
342341 };
343342 bool hasOverlap = false ;
344343
345- for (auto placedItem: gridItemAreas) {
344+ for (const auto & placedItem: gridItemAreas) {
346345 if (proposedPlacement.overlaps (placedItem)) {
347346 hasOverlap = true ;
348347 break ;
@@ -384,7 +383,7 @@ struct AutoPlacement {
384383 };
385384 bool hasOverlap = false ;
386385
387- for (auto placedItem: gridItemAreas) {
386+ for (const auto & placedItem: gridItemAreas) {
388387 if (proposedPlacement.overlaps (placedItem)) {
389388 hasOverlap = true ;
390389 break ;
0 commit comments