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

Unified Diff: sdk/lib/internal/iterable.dart

Issue 2845933002: SkipIterable - ensure field is only initialized to a known int. (Closed)
Patch Set: Created 3 years, 8 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: sdk/lib/internal/iterable.dart
diff --git a/sdk/lib/internal/iterable.dart b/sdk/lib/internal/iterable.dart
index 7f6b8917f357d088185aa4d462b139c42d46dd43..36c39cae5c8e7b248865e50a52a688407f994bde 100644
--- a/sdk/lib/internal/iterable.dart
+++ b/sdk/lib/internal/iterable.dart
@@ -587,11 +587,15 @@ class SkipIterable<E> extends Iterable<E> {
return new SkipIterable<E>._(iterable, count);
}
- SkipIterable._(this._iterable, this._skipCount) {
- if (_skipCount is! int) {
- throw new ArgumentError.value(_skipCount, "count is not an integer");
+ SkipIterable._(this._iterable, int skipCount)
+ : _skipCount = _checkSkip(skipCount);
Lasse Reichstein Nielsen 2017/04/28 06:25:23 How about inlining the check: : _skipCount = ((s
sra1 2017/04/28 18:38:36 The trouble with combined conditions (&&, ||) is t
+
+ static int _checkSkip(int skipCount) {
Lasse Reichstein Nielsen 2017/04/28 06:25:23 If not inlined, maybe name this _checkCount and re
sra1 2017/04/28 18:38:37 Done.
+ if (skipCount is! int) {
+ throw new ArgumentError.value(skipCount, "count is not an integer");
Lasse Reichstein Nielsen 2017/04/28 06:25:23 Second argument is the argument name, not a messag
sra1 2017/04/28 18:38:36 Acknowledged.
}
- RangeError.checkNotNegative(_skipCount, "count");
+ RangeError.checkNotNegative(skipCount, "count");
Lasse Reichstein Nielsen 2017/04/28 06:25:23 Could we combine the two: if (skipCount is! int |
sra1 2017/04/28 18:38:37 See above. dart2js does much better at understandi
Lasse Reichstein Nielsen 2017/05/01 05:32:00 I'm a little concerned about writing code to match
+ return skipCount;
}
Iterable<E> skip(int count) {
« 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