[framework] remove extra casts from framework (#97155)

Remove cast from hit_test matrix code, linkedhashmap cast, and insertion sort cast
This commit is contained in:
Jonah Williams 2022-01-24 16:24:17 -08:00 committed by GitHub
parent 6b6cea65e2
commit 2978629eb2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 7 deletions

View file

@ -236,7 +236,7 @@ void _movingInsertionSort<T>(
int Function(T, T) compare,
int start,
int end,
List<T?> target,
List<T> target,
int targetOffset,
) {
final int length = end - start;
@ -250,7 +250,7 @@ void _movingInsertionSort<T>(
int max = targetOffset + i;
while (min < max) {
final int mid = min + ((max - min) >> 1);
if (compare(element, target[mid] as T) < 0) {
if (compare(element, target[mid]) < 0) {
max = mid;
} else {
min = mid + 1;

View file

@ -90,7 +90,7 @@ class _MatrixTransformPart extends _TransformPart {
@override
Matrix4 multiply(Matrix4 rhs) {
return matrix * rhs as Matrix4;
return matrix.multiplied(rhs);
}
}

View file

@ -2,6 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This library intentionally uses the LinkedHashMap constructor to declare that
// entries will be ordered. Using collection literals for this requires casting the
// resulting map, which has a runtime cost.
// ignore_for_file: prefer_collection_literals
import 'dart:collection' show LinkedHashMap;
import 'dart:ui';
@ -231,8 +236,7 @@ class MouseTracker extends ChangeNotifier {
LinkedHashMap<MouseTrackerAnnotation, Matrix4> _hitTestResultToAnnotations(HitTestResult result) {
assert(result != null);
final LinkedHashMap<MouseTrackerAnnotation, Matrix4> annotations = <MouseTrackerAnnotation, Matrix4>{}
as LinkedHashMap<MouseTrackerAnnotation, Matrix4>;
final LinkedHashMap<MouseTrackerAnnotation, Matrix4> annotations = LinkedHashMap<MouseTrackerAnnotation, Matrix4>();
for (final HitTestEntry entry in result.path) {
if (entry.target is MouseTrackerAnnotation) {
annotations[entry.target as MouseTrackerAnnotation] = entry.transform!;
@ -252,7 +256,7 @@ class MouseTracker extends ChangeNotifier {
final Offset globalPosition = state.latestEvent.position;
final int device = state.device;
if (!_mouseStates.containsKey(device))
return <MouseTrackerAnnotation, Matrix4>{} as LinkedHashMap<MouseTrackerAnnotation, Matrix4>;
return LinkedHashMap<MouseTrackerAnnotation, Matrix4>();
return _hitTestResultToAnnotations(hitTest(globalPosition));
}
@ -325,7 +329,7 @@ class MouseTracker extends ChangeNotifier {
final PointerEvent lastEvent = targetState.replaceLatestEvent(event);
final LinkedHashMap<MouseTrackerAnnotation, Matrix4> nextAnnotations = event is PointerRemovedEvent ?
<MouseTrackerAnnotation, Matrix4>{} as LinkedHashMap<MouseTrackerAnnotation, Matrix4> :
LinkedHashMap<MouseTrackerAnnotation, Matrix4>() :
_hitTestResultToAnnotations(result);
final LinkedHashMap<MouseTrackerAnnotation, Matrix4> lastAnnotations = targetState.replaceAnnotations(nextAnnotations);