Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Unified Diff: runtime/vm/parser.cc

Issue 24915002: Slight optimization of case clause type checks (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
===================================================================
--- runtime/vm/parser.cc (revision 27979)
+++ runtime/vm/parser.cc (working copy)
@@ -6081,14 +6081,20 @@
if (val.clazz() != first_value.clazz()) {
ErrorMsg(val_pos, "all case expressions must be of same type");
}
- Class& cls = Class::Handle(val.clazz());
- const Function& equal_op = Function::Handle(
- Resolver::ResolveDynamicAnyArgs(cls, Symbols::EqualOperator()));
- ASSERT(!equal_op.IsNull());
- cls = equal_op.Owner();
- if (!cls.IsObjectClass()) {
- ErrorMsg(val_pos,
- "type class of case expression must not implement operator ==");
+ if (i == 0) {
+ // The value is of some type other than int, String or double.
+ // Check that the type class does not override the == operator.
+ // Check this only in the first loop iteration since all values
+ // are of the same type, which we check above.
+ Class& cls = Class::Handle(val.clazz());
+ const Function& equal_op = Function::Handle(
+ Resolver::ResolveDynamicAnyArgs(cls, Symbols::EqualOperator()));
+ ASSERT(!equal_op.IsNull());
+ cls = equal_op.Owner();
+ if (!cls.IsObjectClass()) {
+ ErrorMsg(val_pos,
+ "type class of case expression must not implement operator ==");
+ }
}
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698