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
dafda50c
Unverified
Commit
dafda50c
authored
Jan 14, 2022
by
Jonah Williams
Committed by
GitHub
Jan 14, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[framework] remove hashcode override for Element (#96644)
parent
49c58718
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
22 deletions
+16
-22
framework.dart
packages/flutter/lib/src/widgets/framework.dart
+1
-22
framework_test.dart
packages/flutter/test/widgets/framework_test.dart
+15
-0
No files found.
packages/flutter/lib/src/widgets/framework.dart
View file @
dafda50c
...
...
@@ -3137,30 +3137,9 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
/// in a build method if it is known that they will not change.
@nonVirtual
@override
// ignore: avoid_equals_and_hash_code_on_mutable_classes
// ignore: avoid_equals_and_hash_code_on_mutable_classes
, hash_and_equals
bool
operator
==(
Object
other
)
=>
identical
(
this
,
other
);
// Custom implementation of hash code optimized for the ".of" pattern used
// with `InheritedWidgets`.
//
// `Element.dependOnInheritedWidgetOfExactType` relies heavily on hash-based
// `Set` look-ups, putting this getter on the performance critical path.
//
// The value is designed to fit within the SMI representation. This makes
// the cached value use less memory (one field and no extra heap objects) and
// cheap to compare (no indirection).
//
// See also:
//
// * https://dart.dev/articles/dart-vm/numeric-computation, which
// explains how numbers are represented in Dart.
@nonVirtual
@override
// ignore: avoid_equals_and_hash_code_on_mutable_classes
int
get
hashCode
=>
_cachedHash
;
final
int
_cachedHash
=
_nextHashCode
=
(
_nextHashCode
+
1
)
%
0xffffff
;
static
int
_nextHashCode
=
1
;
/// Information set by parent to define where this child fits in its parent's
/// child list.
///
...
...
packages/flutter/test/widgets/framework_test.dart
View file @
dafda50c
...
...
@@ -1656,6 +1656,21 @@ The findRenderObject() method was called for the following element:
)),
);
});
testWidgets
(
'Elements use the identity hashCode'
,
(
WidgetTester
tester
)
async
{
final
StatefulElement
statefulElement
=
StatefulElement
(
const
_StatefulLeaf
());
expect
(
statefulElement
.
hashCode
,
identityHashCode
(
statefulElement
));
final
StatelessElement
statelessElement
=
StatelessElement
(
const
Placeholder
());
expect
(
statelessElement
.
hashCode
,
identityHashCode
(
statelessElement
));
final
InheritedElement
inheritedElement
=
InheritedElement
(
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Placeholder
()),
);
expect
(
inheritedElement
.
hashCode
,
identityHashCode
(
inheritedElement
));
});
}
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