Skip to content

Commit 2495c5c

Browse files
nshahancommit-bot@chromium.org
authored andcommitted
[html] Avoid dynamic in Rectangle operator ==
* Rely on type promotion instead. * The is! type promotion isn't working in the CFE yet. Change-Id: Ia4c8b4bcbac50cd0ab07c60f7440ef3837675b7a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122179 Commit-Queue: Nicholas Shahan <nshahan@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com>
1 parent aa569df commit 2495c5c

File tree

5 files changed

+60
-65
lines changed

5 files changed

+60
-65
lines changed

sdk/lib/html/dart2js/html_dart2js.dart

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10842,13 +10842,12 @@ class DomRectReadOnly extends Interceptor implements Rectangle {
1084210842
return 'Rectangle ($left, $top) $width x $height';
1084310843
}
1084410844

10845-
bool operator ==(other) {
10846-
if (other is! Rectangle) return false;
10847-
return left == other.left &&
10848-
top == other.top &&
10849-
width == other.width &&
10850-
height == other.height;
10851-
}
10845+
bool operator ==(other) =>
10846+
other is Rectangle &&
10847+
left == other.left &&
10848+
top == other.top &&
10849+
width == other.width &&
10850+
height == other.height;
1085210851

1085310852
int get hashCode => _JenkinsSmiHash.hash4(
1085410853
left.hashCode, top.hashCode, width.hashCode, height.hashCode);
@@ -32939,13 +32938,12 @@ class _DomRect extends DomRectReadOnly implements Rectangle {
3293932938
return 'Rectangle ($left, $top) $width x $height';
3294032939
}
3294132940

32942-
bool operator ==(other) {
32943-
if (other is! Rectangle) return false;
32944-
return left == other.left &&
32945-
top == other.top &&
32946-
width == other.width &&
32947-
height == other.height;
32948-
}
32941+
bool operator ==(other) =>
32942+
other is Rectangle &&
32943+
left == other.left &&
32944+
top == other.top &&
32945+
width == other.width &&
32946+
height == other.height;
3294932947

3295032948
int get hashCode => _JenkinsSmiHash.hash4(
3295132949
left.hashCode, top.hashCode, width.hashCode, height.hashCode);
@@ -34970,8 +34968,8 @@ abstract class CssRect implements Rectangle<num> {
3497034968
}
3497134969

3497234970
// TODO(jacobr): these methods are duplicated from _RectangleBase in dart:math
34973-
// Ideally we would provide a RectangleMixin class that provides this implementation.
34974-
// In an ideal world we would exp
34971+
// Ideally we would provide a RectangleMixin class that provides this
34972+
// implementation. In an ideal world we would exp
3497534973
/** The x-coordinate of the right edge. */
3497634974
num get right => left + width;
3497734975
/** The y-coordinate of the bottom edge. */
@@ -34981,13 +34979,12 @@ abstract class CssRect implements Rectangle<num> {
3498134979
return 'Rectangle ($left, $top) $width x $height';
3498234980
}
3498334981

34984-
bool operator ==(other) {
34985-
if (other is! Rectangle) return false;
34986-
return left == other.left &&
34987-
top == other.top &&
34988-
right == other.right &&
34989-
bottom == other.bottom;
34990-
}
34982+
bool operator ==(other) =>
34983+
other is Rectangle &&
34984+
left == other.left &&
34985+
top == other.top &&
34986+
right == other.right &&
34987+
bottom == other.bottom;
3499134988

3499234989
int get hashCode => _JenkinsSmiHash.hash4(
3499334990
left.hashCode, top.hashCode, right.hashCode, bottom.hashCode);

sdk_nnbd/lib/html/dart2js/html_dart2js.dart

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10844,13 +10844,12 @@ class DomRectReadOnly extends Interceptor implements Rectangle {
1084410844
return 'Rectangle ($left, $top) $width x $height';
1084510845
}
1084610846

10847-
bool operator ==(other) {
10848-
if (other is! Rectangle) return false;
10849-
return left == other.left &&
10850-
top == other.top &&
10851-
width == other.width &&
10852-
height == other.height;
10853-
}
10847+
bool operator ==(other) =>
10848+
other is Rectangle &&
10849+
left == other.left &&
10850+
top == other.top &&
10851+
width == other.width &&
10852+
height == other.height;
1085410853

1085510854
int get hashCode => _JenkinsSmiHash.hash4(
1085610855
left.hashCode, top.hashCode, width.hashCode, height.hashCode);
@@ -32941,13 +32940,12 @@ class _DomRect extends DomRectReadOnly implements Rectangle {
3294132940
return 'Rectangle ($left, $top) $width x $height';
3294232941
}
3294332942

32944-
bool operator ==(other) {
32945-
if (other is! Rectangle) return false;
32946-
return left == other.left &&
32947-
top == other.top &&
32948-
width == other.width &&
32949-
height == other.height;
32950-
}
32943+
bool operator ==(other) =>
32944+
other is Rectangle &&
32945+
left == other.left &&
32946+
top == other.top &&
32947+
width == other.width &&
32948+
height == other.height;
3295132949

3295232950
int get hashCode => _JenkinsSmiHash.hash4(
3295332951
left.hashCode, top.hashCode, width.hashCode, height.hashCode);
@@ -34972,8 +34970,8 @@ abstract class CssRect implements Rectangle<num> {
3497234970
}
3497334971

3497434972
// TODO(jacobr): these methods are duplicated from _RectangleBase in dart:math
34975-
// Ideally we would provide a RectangleMixin class that provides this implementation.
34976-
// In an ideal world we would exp
34973+
// Ideally we would provide a RectangleMixin class that provides this
34974+
// implementation. In an ideal world we would exp
3497734975
/** The x-coordinate of the right edge. */
3497834976
num get right => left + width;
3497934977
/** The y-coordinate of the bottom edge. */
@@ -34983,13 +34981,12 @@ abstract class CssRect implements Rectangle<num> {
3498334981
return 'Rectangle ($left, $top) $width x $height';
3498434982
}
3498534983

34986-
bool operator ==(other) {
34987-
if (other is! Rectangle) return false;
34988-
return left == other.left &&
34989-
top == other.top &&
34990-
right == other.right &&
34991-
bottom == other.bottom;
34992-
}
34984+
bool operator ==(other) =>
34985+
other is Rectangle &&
34986+
left == other.left &&
34987+
top == other.top &&
34988+
right == other.right &&
34989+
bottom == other.bottom;
3499334990

3499434991
int get hashCode => _JenkinsSmiHash.hash4(
3499534992
left.hashCode, top.hashCode, right.hashCode, bottom.hashCode);

tools/dom/src/CssRectangle.dart

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ abstract class CssRect implements Rectangle<num> {
269269
}
270270

271271
// TODO(jacobr): these methods are duplicated from _RectangleBase in dart:math
272-
// Ideally we would provide a RectangleMixin class that provides this implementation.
273-
// In an ideal world we would exp
272+
// Ideally we would provide a RectangleMixin class that provides this
273+
// implementation. In an ideal world we would exp
274274
/** The x-coordinate of the right edge. */
275275
num get right => left + width;
276276
/** The y-coordinate of the bottom edge. */
@@ -280,13 +280,12 @@ abstract class CssRect implements Rectangle<num> {
280280
return 'Rectangle ($left, $top) $width x $height';
281281
}
282282

283-
bool operator ==(other) {
284-
if (other is! Rectangle) return false;
285-
return left == other.left &&
286-
top == other.top &&
287-
right == other.right &&
288-
bottom == other.bottom;
289-
}
283+
bool operator ==(other) =>
284+
other is Rectangle &&
285+
left == other.left &&
286+
top == other.top &&
287+
right == other.right &&
288+
bottom == other.bottom;
290289

291290
int get hashCode => _JenkinsSmiHash.hash4(
292291
left.hashCode, top.hashCode, right.hashCode, bottom.hashCode);

tools/dom/templates/html/impl/impl_DOMRect.darttemplate

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS implements
1111
return 'Rectangle ($left, $top) $width x $height';
1212
}
1313

14-
bool operator ==(other) {
15-
if (other is !Rectangle) return false;
16-
return left == other.left && top == other.top && width == other.width &&
17-
height == other.height;
18-
}
14+
bool operator ==(other) =>
15+
other is Rectangle &&
16+
left == other.left &&
17+
top == other.top &&
18+
width == other.width &&
19+
height == other.height;
1920

2021
int get hashCode => _JenkinsSmiHash.hash4(left.hashCode, top.hashCode,
2122
width.hashCode, height.hashCode);

tools/dom/templates/html/impl/impl_DOMRectReadOnly.darttemplate

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS implements
1111
return 'Rectangle ($left, $top) $width x $height';
1212
}
1313

14-
bool operator ==(other) {
15-
if (other is !Rectangle) return false;
16-
return left == other.left && top == other.top && width == other.width &&
17-
height == other.height;
18-
}
14+
bool operator ==(other) =>
15+
other is Rectangle &&
16+
left == other.left &&
17+
top == other.top &&
18+
width == other.width &&
19+
height == other.height;
1920

2021
int get hashCode => _JenkinsSmiHash.hash4(left.hashCode, top.hashCode,
2122
width.hashCode, height.hashCode);

0 commit comments

Comments
 (0)