Fix a performance bug with FileLocation.
The bug was actually located in SourceLocation. The constructor
accesses this.line and `this.column` in preference to the arguments it
was passed, which was fine for normal SourceLocations but for
FileLocations caused two binary searches to be performed every time a
location was instantiated.
R=rnystrom@google.com
Review URL: https://codereview.chromium.org//1328613002 .
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 59923d5..6bd18f1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+# 1.2.0
+
+* Dramatically improve the performance of `FileLocation`.
+
# 1.1.6
* Optimize `getLine()` in `SourceFile` when repeatedly called.
diff --git a/lib/src/location.dart b/lib/src/location.dart
index 42e2b7d..024c6e2 100644
--- a/lib/src/location.dart
+++ b/lib/src/location.dart
@@ -43,12 +43,12 @@
offset = offset,
line = line == null ? 0 : line,
column = column == null ? offset : column {
- if (this.offset < 0) {
- throw new RangeError("Offset may not be negative, was ${this.offset}.");
- } else if (this.line < 0) {
- throw new RangeError("Line may not be negative, was ${this.line}.");
- } else if (this.column < 0) {
- throw new RangeError("Column may not be negative, was ${this.column}.");
+ if (offset < 0) {
+ throw new RangeError("Offset may not be negative, was $offset.");
+ } else if (line != null && line < 0) {
+ throw new RangeError("Line may not be negative, was $line.");
+ } else if (column != null && column < 0) {
+ throw new RangeError("Column may not be negative, was $column.");
}
}
diff --git a/pubspec.yaml b/pubspec.yaml
index a084bdf..7ffbc64 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: source_span
-version: 1.1.6
+version: 1.2.0-dev
author: Dart Team <misc@dartlang.org>
description: A library for identifying source spans and locations.
homepage: https://github.com/dart-lang/source_span