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

Unified Diff: pkg/analyzer/lib/src/generated/source_io.dart

Issue 954063002: Use an interning table to compare and hash FileBasedSource objects. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/source_io.dart
diff --git a/pkg/analyzer/lib/src/generated/source_io.dart b/pkg/analyzer/lib/src/generated/source_io.dart
index 06211df7252cde81872ea95a13dd93847f5ef585..e22736b7a3050debedec514de918ff9990d3f3cd 100644
--- a/pkg/analyzer/lib/src/generated/source_io.dart
+++ b/pkg/analyzer/lib/src/generated/source_io.dart
@@ -7,6 +7,8 @@
library engine.source.io;
+import 'dart:collection';
+
import 'engine.dart';
import 'java_core.dart';
import 'java_engine.dart';
@@ -93,11 +95,25 @@ class FileBasedSource extends Source {
static Function fileReadMode = (String s) => s;
/**
+ * Map from encoded URI/filepath pair to a unique integer identifier. This
+ * identifier is used for equality tests and hash codes.
+ *
+ * The URI and filepath are joined into a pair by separating them with an '@'
+ * character.
+ */
+ static final Map<String, int> _idTable = new HashMap<String, int>();
+
+ /**
* The URI from which this source was originally derived.
*/
final Uri uri;
/**
+ * The unique ID associated with this [FileBasedSource].
+ */
+ final int id;
+
+ /**
* The file represented by this source.
*/
final JavaFile file;
@@ -125,7 +141,11 @@ class FileBasedSource extends Source {
* @param file the file represented by this source
* @param uri the URI from which this source was originally derived
*/
- FileBasedSource.con2(this.uri, this.file);
+ FileBasedSource.con2(Uri uri, JavaFile file)
+ : uri = uri, file = file,
+ id = _idTable.putIfAbsent(
+ '$uri@${file.getPath()}',
+ () => _idTable.length);
@override
TimestampedData<String> get contents {
@@ -168,7 +188,7 @@ class FileBasedSource extends Source {
}
@override
- int get hashCode => file.hashCode;
+ int get hashCode => id;
@override
bool get isInSystemLibrary => uri.scheme == DartUriResolver.DART_SCHEME;
@@ -194,7 +214,7 @@ class FileBasedSource extends Source {
@override
bool operator ==(Object object) =>
- object is FileBasedSource && uri == object.uri;
+ object is FileBasedSource && id == object.id;
@override
bool exists() => file.isFile();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698