Skip to content

Commit d26fd0e

Browse files
committed
optimize constriants build
1 parent c66121a commit d26fd0e

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

lib/src/constraint_layout.dart

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2390,18 +2390,27 @@ class _ConstraintRenderBox extends RenderBox
23902390
id = _IndexConstraintId(targetIndex);
23912391
}
23922392

2393-
/// Fewer reads to nodesMap for faster constraint building
2394-
_ConstrainedNode? node = id.getCacheNode(_buildNodeTreesCount ^ hashCode);
2395-
if (node != null) {
2396-
return node;
2393+
_ConstrainedNode? node;
2394+
int? contextHash;
2395+
if (id.runtimeType == ConstraintId) {
2396+
/// Fewer reads to nodesMap for faster constraint building
2397+
contextHash = _buildNodeTreesCount ^ hashCode;
2398+
node = id.getCacheNode(contextHash);
2399+
if (node != null) {
2400+
return node;
2401+
}
23972402
}
23982403

23992404
node = nodesMap[id];
24002405
if (node == null) {
24012406
node = _ConstrainedNode()..nodeId = id;
24022407
nodesMap[id] = node;
24032408
}
2404-
id.setCacheNode(_buildNodeTreesCount ^ hashCode, node);
2409+
2410+
if (id.runtimeType == ConstraintId) {
2411+
id.setCacheNode(contextHash!, node);
2412+
}
2413+
24052414
return node;
24062415
}
24072416

0 commit comments

Comments
 (0)