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

Unified Diff: pkg/source_span/lib/src/file.dart

Issue 754463002: Avoid instantiating FileLocations where possible in source_span. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 6 years, 1 month 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 | « pkg/source_span/CHANGELOG.md ('k') | pkg/source_span/lib/src/span_mixin.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/source_span/lib/src/file.dart
diff --git a/pkg/source_span/lib/src/file.dart b/pkg/source_span/lib/src/file.dart
index 14aa22627fe4747d8e42f9442d9952cbf9c6f00d..ed5f6a8371226ed65065789a6ec8ee043701426f 100644
--- a/pkg/source_span/lib/src/file.dart
+++ b/pkg/source_span/lib/src/file.dart
@@ -199,10 +199,11 @@ class FileSpan extends SourceSpanMixin {
/// objects.
final int _end;
+ Uri get sourceUrl => file.url;
+ int get length => _end - _start;
FileLocation get start => new FileLocation._(file, _start);
FileLocation get end => new FileLocation._(file, _end);
-
- String get text => file.getText(start.offset, end.offset);
+ String get text => file.getText(_start, _end);
FileSpan._(this.file, this._start, this._end) {
if (_end < _start) {
@@ -215,20 +216,37 @@ class FileSpan extends SourceSpanMixin {
}
}
+ int compareTo(SourceSpan other) {
+ if (other is! FileSpan) return super.compareTo(other);
+
+ FileSpan otherFile = other;
+ var result = _start.compareTo(otherFile._start);
+ return result == 0 ? _end.compareTo(otherFile._end) : result;
+ }
+
SourceSpan union(SourceSpan other) {
if (other is! FileSpan) return super.union(other);
var span = expand(other);
- var beginSpan = span.start == this.start ? this : other;
- var endSpan = span.end == this.end ? this : other;
+ var beginSpan = span._start == _start ? this : other;
+ var endSpan = span._end == _end ? this : other;
- if (beginSpan.end.compareTo(endSpan.start) < 0) {
+ if (beginSpan._end < endSpan._start) {
throw new ArgumentError("Spans $this and $other are disjoint.");
}
return span;
}
+ bool operator ==(other) {
+ if (other is! FileSpan) return super == other;
+ return _start == other._start && _end == other._end &&
+ sourceUrl == other.sourceUrl;
+ }
+
+ int get hashCode => _start.hashCode + 5 * _end.hashCode +
+ 7 * sourceUrl.hashCode;
+
/// Returns a new span that covers both [this] and [other].
///
/// Unlike [union], [other] may be disjoint from [this]. If it is, the text
@@ -241,7 +259,7 @@ class FileSpan extends SourceSpanMixin {
var start = math.min(this._start, other._start);
var end = math.max(this._end, other._end);
- return new FileSpan._(file, start, end);
+ return new FileSpan._(file, start, end);
}
String message(String message, {color}) {
« no previous file with comments | « pkg/source_span/CHANGELOG.md ('k') | pkg/source_span/lib/src/span_mixin.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698