Index: lib/src/file.dart |
diff --git a/lib/src/file.dart b/lib/src/file.dart |
index 4b4e026cbd4013ea33da63dc93446f07499cf963..2c7a92b2a6199915c4bfc0af8d5b00eb30c664e4 100644 |
--- a/lib/src/file.dart |
+++ b/lib/src/file.dart |
@@ -7,9 +7,6 @@ library source_span.file; |
import 'dart:math' as math; |
import 'dart:typed_data'; |
-import 'package:path/path.dart' as p; |
- |
-import 'colors.dart' as colors; |
import 'location.dart'; |
import 'span.dart'; |
import 'span_mixin.dart'; |
@@ -220,7 +217,8 @@ class FileSpan extends SourceSpanMixin implements SourceSpanWithContext { |
} |
int compareTo(SourceSpan other) { |
- if (other is! FileSpan) return super.compareTo(other); |
+ // Check runtimeType to be resilient to external FileSpan implementations. |
+ if (other.runtimeType != FileSpan) return super.compareTo(other); |
Siggi Cherem (dart-lang)
2015/08/18 18:01:59
Could we instead move some of the shared code into
nweiz
2015/08/18 20:28:51
I don't think a mixin would work, but I've split o
|
FileSpan otherFile = other; |
var result = _start.compareTo(otherFile._start); |
@@ -242,13 +240,14 @@ class FileSpan extends SourceSpanMixin implements SourceSpanWithContext { |
} |
bool operator ==(other) { |
+ // Check runtimeType to be resilient to external FileSpan implementations. |
if (other is! FileSpan) return super == other; |
- return _start == other._start && _end == other._end && |
- sourceUrl == other.sourceUrl; |
- } |
+ if (other.runtimeType != FileSpan) { |
+ return super == other && sourceUrl == other.sourceUrl; |
+ } |
- int get hashCode => _start.hashCode + 5 * _end.hashCode + |
- 7 * sourceUrl.hashCode; |
+ return _start == other._start && _end == other._end; |
Siggi Cherem (dart-lang)
2015/08/18 18:01:59
mmm - I thought we would keep the check on sourceU
nweiz
2015/08/18 20:28:51
Yeah, good catch. Just a cut/paste error.
|
+ } |
/// Returns a new span that covers both [this] and [other]. |
/// |
@@ -260,8 +259,15 @@ class FileSpan extends SourceSpanMixin implements SourceSpanWithContext { |
" \"${other.sourceUrl}\" don't match."); |
} |
- var start = math.min(this._start, other._start); |
- var end = math.max(this._end, other._end); |
- return new FileSpan._(file, start, end); |
+ // Check runtimeType to be resilient to external FileSpan implementations. |
+ if (other.runtimeType == FileSpan) { |
+ var start = math.min(this._start, other._start); |
Siggi Cherem (dart-lang)
2015/08/18 18:01:59
I wonder if we should have these optimizations or
nweiz
2015/08/18 20:28:51
In my experiments, there's a lot of benefit that c
|
+ var end = math.max(this._end, other._end); |
+ return new FileSpan._(file, start, end); |
+ } else { |
+ var start = math.min(this._start, other.start.offset); |
+ var end = math.max(this._end, other.end.offset); |
+ return new FileSpan._(file, start, end); |
+ } |
} |
} |