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

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

Issue 706133002: Use a more compact internal representation for FileSpan. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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/pubspec.yaml » ('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 0d2d6f6ca3372bec5dbac3305c31add2c2f835ee..5680733d49733b39a48e867606d20865ddba9a82 100644
--- a/pkg/source_span/lib/src/file.dart
+++ b/pkg/source_span/lib/src/file.dart
@@ -73,7 +73,7 @@ class SourceFile {
/// If [end] isn't passed, it defaults to the end of the file.
FileSpan span(int start, [int end]) {
if (end == null) end = length - 1;
- return new FileSpan._(this, location(start), location(end));
+ return new FileSpan._(this, start, end);
}
/// Returns a location in [this] at [offset].
@@ -172,7 +172,7 @@ class FileLocation extends SourceLocation {
}
}
- FileSpan pointSpan() => new FileSpan._(file, this, this);
+ FileSpan pointSpan() => new FileSpan._(file, offset, offset);
}
/// A [SourceSpan] within a [SourceFile].
@@ -187,14 +187,26 @@ class FileSpan extends SourceSpanMixin {
/// The [file] that [this] belongs to.
final SourceFile file;
- final FileLocation start;
- final FileLocation end;
+ /// The offset of the beginning of the span.
+ ///
+ /// [start] is lazily generated from this to avoid allocating unnecessary
+ /// objects.
+ final int _start;
+
+ /// The offset of the end of the span.
+ ///
+ /// [end] is lazily generated from this to avoid allocating unnecessary
+ /// objects.
+ final int _end;
+
+ FileLocation get start => new FileLocation._(file, _start);
+ FileLocation get end => new FileLocation._(file, _end);
String get text => file.getText(start.offset, end.offset);
- FileSpan._(this.file, this.start, this.end) {
- if (end.offset < start.offset) {
- throw new ArgumentError('End $end must come after start $start.');
+ FileSpan._(this.file, this._start, this._end) {
+ if (_end < _start) {
+ throw new ArgumentError('End $_end must come after start $_start.');
}
}
@@ -222,8 +234,8 @@ class FileSpan extends SourceSpanMixin {
" \"${other.sourceUrl}\" don't match.");
}
- var start = min(this.start, other.start);
- var end = max(this.end, other.end);
+ var start = math.min(this._start, other._start);
+ var end = math.max(this._end, other._end);
return new FileSpan._(file, start, end);
}
« no previous file with comments | « pkg/source_span/CHANGELOG.md ('k') | pkg/source_span/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698