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

Unified Diff: sdk/lib/_internal/compiler/implementation/source_map_builder.dart

Issue 228003005: Remove redundancy in source map entries. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changed command path. Created 6 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
Index: sdk/lib/_internal/compiler/implementation/source_map_builder.dart
diff --git a/sdk/lib/_internal/compiler/implementation/source_map_builder.dart b/sdk/lib/_internal/compiler/implementation/source_map_builder.dart
index 3910615899285e634f082a70081b575ca00e45fe..16697e940c4ed3e4f79e4352b8a6642dd3aeb62e 100644
--- a/sdk/lib/_internal/compiler/implementation/source_map_builder.dart
+++ b/sdk/lib/_internal/compiler/implementation/source_map_builder.dart
@@ -20,6 +20,7 @@ class SourceMapBuilder {
final Uri uri;
final Uri fileUri;
+ SourceFile targetFile;
List<SourceMapEntry> entries;
Map<String, int> sourceUrlMap;
@@ -35,7 +36,7 @@ class SourceMapBuilder {
int previousSourceNameIndex;
bool firstEntryInLine;
- SourceMapBuilder(this.uri, this.fileUri) {
+ SourceMapBuilder(this.uri, this.fileUri, this.targetFile) {
entries = new List<SourceMapEntry>();
sourceUrlMap = new Map<String, int>();
@@ -52,7 +53,59 @@ class SourceMapBuilder {
firstEntryInLine = true;
}
+ resetPreviousSourceLocation() {
+ previousSourceUrlIndex = 0;
+ previousSourceLine = 0;
+ previousSourceColumn = 0;
+ previousSourceNameIndex = 0;
+ }
+
+ updatePreviousSourceLocation(SourceFileLocation sourceLocation) {
+ previousSourceLine = sourceLocation.getLine();
+ previousSourceColumn = sourceLocation.getColumn();
+ String sourceUrl = sourceLocation.getSourceUrl();
+ previousSourceUrlIndex = indexOf(sourceUrlList, sourceUrl, sourceUrlMap);
+ String sourceName = sourceLocation.getSourceName();
+ if (sourceName != null) {
+ previousSourceNameIndex =
+ indexOf(sourceNameList, sourceName, sourceNameMap);
+ }
+ }
+
+ bool sameAsPreviousLocation(SourceFileLocation sourceLocation) {
+ if (sourceLocation == null) {
+ return true;
+ }
+ int sourceUrlIndex =
+ indexOf(sourceUrlList, sourceLocation.getSourceUrl(), sourceUrlMap);
+ return
+ sourceUrlIndex == previousSourceUrlIndex &&
+ sourceLocation.getLine() == previousSourceLine &&
+ sourceLocation.getColumn() == previousSourceColumn;
+ }
+
void addMapping(int targetOffset, SourceFileLocation sourceLocation) {
+
+ bool sameLine(int position, otherPosition) {
+ return targetFile.getLine(position) == targetFile.getLine(otherPosition);
+ }
+
+ if (!entries.isEmpty && sameLine(targetOffset, entries.last.targetOffset)) {
+ if (sameAsPreviousLocation(sourceLocation)) {
+ // The entry points to the same source location as the previous entry in
+ // the same line, hence it is not needed for the source map.
+ //
+ // TODO(zarah): Remove this check and make sure that [addMapping] is not
+ // called for this position. Instead, when consecutive lines in the
+ // generated code point to the same source location, record this and use
+ // it to generate the entries of the source map.
+ return;
+ }
+ }
+
+ if (sourceLocation != null) {
+ updatePreviousSourceLocation(sourceLocation);
+ }
entries.add(new SourceMapEntry(sourceLocation, targetOffset));
}
@@ -69,7 +122,8 @@ class SourceMapBuilder {
buffer.write(']');
}
- String build(SourceFile targetFile) {
+ String build() {
+ resetPreviousSourceLocation();
StringBuffer mappingsBuffer = new StringBuffer();
entries.forEach((SourceMapEntry entry) => writeEntry(entry, targetFile,
mappingsBuffer));
@@ -127,12 +181,9 @@ class SourceMapBuilder {
int sourceUrlIndex = indexOf(sourceUrlList, sourceUrl, sourceUrlMap);
encodeVLQ(output, sourceUrlIndex - previousSourceUrlIndex);
- previousSourceUrlIndex = sourceUrlIndex;
-
encodeVLQ(output, sourceLine - previousSourceLine);
- previousSourceLine = sourceLine;
encodeVLQ(output, sourceColumn - previousSourceColumn);
- previousSourceColumn = sourceColumn;
+ updatePreviousSourceLocation(entry.sourceLocation);
if (sourceName == null) {
return;
@@ -140,7 +191,7 @@ class SourceMapBuilder {
int sourceNameIndex = indexOf(sourceNameList, sourceName, sourceNameMap);
encodeVLQ(output, sourceNameIndex - previousSourceNameIndex);
- previousSourceNameIndex = sourceNameIndex;
+
}
int indexOf(List<String> list, String value, Map<String, int> map) {

Powered by Google App Engine
This is Rietveld 408576698