Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
18713e0c
Unverified
Commit
18713e0c
authored
Apr 25, 2022
by
gaaclarke
Committed by
GitHub
Apr 25, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made Directionality forego dependency tracking for better performance. (#102336)
parent
1c80e29b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
1 deletion
+87
-1
basic.dart
packages/flutter/lib/src/widgets/basic.dart
+58
-1
framework.dart
packages/flutter/lib/src/widgets/framework.dart
+5
-0
framework_test.dart
packages/flutter/test/widgets/framework_test.dart
+24
-0
No files found.
packages/flutter/lib/src/widgets/basic.dart
View file @
18713e0c
...
@@ -80,12 +80,69 @@ export 'package:flutter/services.dart' show
...
@@ -80,12 +80,69 @@ export 'package:flutter/services.dart' show
// BIDIRECTIONAL TEXT SUPPORT
// BIDIRECTIONAL TEXT SUPPORT
/// An [InheritedElement] that has hundreds of dependencies but will
/// infrequently change. This provides a performance tradeoff where building
/// the [Widget]s is faster but performing updates is slower.
///
/// | | _UbiquitiousInheritedElement | InheritedElement |
/// |---------------------|------------------------------|------------------|
/// | insert (best case) | O(1) | O(1) |
/// | insert (worst case) | O(1) | O(n) |
/// | search (best case) | O(n) | O(1) |
/// | search (worst case) | O(n) | O(n) |
///
/// Insert happens when building the [Widget] tree, search happens when updating
/// [Widget]s.
class
_UbiquitousInheritedElement
extends
InheritedElement
{
/// Creates an element that uses the given widget as its configuration.
_UbiquitousInheritedElement
(
super
.
widget
);
@override
void
setDependencies
(
Element
dependent
,
Object
?
value
)
{
// This is where the cost of [InheritedElement] is incurred during build
// time of the widget tree. Omitting this bookkeeping is where the
// performance savings come from.
assert
(
value
==
null
);
}
@override
Object
?
getDependencies
(
Element
dependent
)
{
return
null
;
}
@override
void
notifyClients
(
InheritedWidget
oldWidget
)
{
_recurseChildren
(
this
,
(
Element
element
)
{
if
(
element
.
doesDependOnInheritedElement
(
this
))
{
notifyDependent
(
oldWidget
,
element
);
}
});
}
static
void
_recurseChildren
(
Element
element
,
ElementVisitor
visitor
)
{
element
.
visitChildren
((
Element
child
)
{
_recurseChildren
(
child
,
visitor
);
});
visitor
(
element
);
}
}
/// See also:
///
/// * [_UbiquitousInheritedElement], the [Element] for [_UbiquitousInheritedWidget].
abstract
class
_UbiquitousInheritedWidget
extends
InheritedWidget
{
const
_UbiquitousInheritedWidget
({
super
.
key
,
required
super
.
child
});
@override
InheritedElement
createElement
()
=>
_UbiquitousInheritedElement
(
this
);
}
/// A widget that determines the ambient directionality of text and
/// A widget that determines the ambient directionality of text and
/// text-direction-sensitive render objects.
/// text-direction-sensitive render objects.
///
///
/// For example, [Padding] depends on the [Directionality] to resolve
/// For example, [Padding] depends on the [Directionality] to resolve
/// [EdgeInsetsDirectional] objects into absolute [EdgeInsets] objects.
/// [EdgeInsetsDirectional] objects into absolute [EdgeInsets] objects.
class
Directionality
extends
InheritedWidget
{
class
Directionality
extends
_Ubiquitous
InheritedWidget
{
/// Creates a widget that determines the directionality of text and
/// Creates a widget that determines the directionality of text and
/// text-direction-sensitive render objects.
/// text-direction-sensitive render objects.
///
///
...
...
packages/flutter/lib/src/widgets/framework.dart
View file @
18713e0c
...
@@ -4197,6 +4197,11 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
...
@@ -4197,6 +4197,11 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
return
true
;
return
true
;
}
}
/// Returns `true` if [dependOnInheritedElement] was previously called with [ancestor].
@protected
bool
doesDependOnInheritedElement
(
InheritedElement
ancestor
)
=>
_dependencies
!=
null
&&
_dependencies
!.
contains
(
ancestor
);
@override
@override
InheritedWidget
dependOnInheritedElement
(
InheritedElement
ancestor
,
{
Object
?
aspect
})
{
InheritedWidget
dependOnInheritedElement
(
InheritedElement
ancestor
,
{
Object
?
aspect
})
{
assert
(
ancestor
!=
null
);
assert
(
ancestor
!=
null
);
...
...
packages/flutter/test/widgets/framework_test.dart
View file @
18713e0c
...
@@ -1694,6 +1694,30 @@ The findRenderObject() method was called for the following element:
...
@@ -1694,6 +1694,30 @@ The findRenderObject() method was called for the following element:
expect
(
inheritedElement
.
hashCode
,
identityHashCode
(
inheritedElement
));
expect
(
inheritedElement
.
hashCode
,
identityHashCode
(
inheritedElement
));
});
});
testWidgets
(
'doesDependOnInheritedElement'
,
(
WidgetTester
tester
)
async
{
final
_TestInheritedElement
ancestor
=
_TestInheritedElement
(
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Placeholder
(),
));
final
_TestInheritedElement
child
=
_TestInheritedElement
(
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Placeholder
(),
));
expect
(
child
.
doesDependOnInheritedElement
(
ancestor
),
isFalse
);
child
.
dependOnInheritedElement
(
ancestor
);
expect
(
child
.
doesDependOnInheritedElement
(
ancestor
),
isTrue
);
});
}
class
_TestInheritedElement
extends
InheritedElement
{
_TestInheritedElement
(
super
.
widget
);
@override
bool
doesDependOnInheritedElement
(
InheritedElement
element
)
{
return
super
.
doesDependOnInheritedElement
(
element
);
}
}
}
class
_WidgetWithNoVisitChildren
extends
StatelessWidget
{
class
_WidgetWithNoVisitChildren
extends
StatelessWidget
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment