Cache the package:path context.current field in toUri() calls.

Change-Id: I9a3c2e0b587d3821340b275af88ce3cff5ec1bcf
Reviewed-on: https://dart-review.googlesource.com/65030
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/dart/analysis/file_state.dart b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
index 530e205..39ce165 100644
--- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
@@ -766,15 +766,16 @@
   FileSystemStateTestView _testView;
 
   FileSystemState(
-      this._logger,
-      this._byteStore,
-      this._contentOverlay,
-      this._resourceProvider,
-      this._sourceFactory,
-      this._analysisOptions,
-      this._salt,
-      {this.externalSummaries,
-      this.parseExceptionHandler}) {
+    this._logger,
+    this._byteStore,
+    this._contentOverlay,
+    this._resourceProvider,
+    this._sourceFactory,
+    this._analysisOptions,
+    this._salt, {
+    this.externalSummaries,
+    this.parseExceptionHandler,
+  }) {
     _fileContentCache =
         _FileContentCache.getInstance(_resourceProvider, _contentOverlay);
     _testView = new FileSystemStateTestView(this);
@@ -815,9 +816,9 @@
         return file;
       }
       // Create a new file.
-      Uri fileUri = _resourceProvider.pathContext.toUri(path);
       FileSource uriSource = new FileSource(resource, uri);
-      file = new FileState._(this, path, uri, fileUri, uriSource);
+      file = new FileState._(
+          this, path, uri, _absolutePathToFileUri(path), uriSource);
       _uriToFile[uri] = file;
       _addFileWithPath(path, file);
       _pathToCanonicalFile[path] = file;
@@ -856,9 +857,9 @@
 
       String path = uriSource.fullName;
       File resource = _resourceProvider.getFile(path);
-      Uri fileUri = _resourceProvider.pathContext.toUri(path);
       FileSource source = new FileSource(resource, uri);
-      file = new FileState._(this, path, uri, fileUri, source);
+      file = new FileState._(
+          this, path, uri, _absolutePathToFileUri(path), source);
       _uriToFile[uri] = file;
       _addFileWithPath(path, file);
       file.refresh(allowCached: true);
@@ -933,6 +934,18 @@
     }
     files.add(file);
   }
+
+  /**
+   * A specialized version of package:path context.toUri(). This assumes the
+   * path is absolute as does a performant conversion to a file: uri.
+   */
+  Uri _absolutePathToFileUri(String path) {
+    if (path.contains(r'\')) {
+      return new Uri(scheme: 'file', path: path.replaceAll(r'\', '/'));
+    } else {
+      return new Uri(scheme: 'file', path: path);
+    }
+  }
 }
 
 @visibleForTesting