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

Unified Diff: pkg/front_end/lib/src/incremental/file_state.dart

Issue 2867303002: FileState needs only bytes of the file. (Closed)
Patch Set: Created 3 years, 7 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/front_end/lib/src/incremental/file_state.dart
diff --git a/pkg/front_end/lib/src/incremental/file_state.dart b/pkg/front_end/lib/src/incremental/file_state.dart
index fec7c17940977ef7b681a9df3f08231f8a15ab41..fa4a1f1b249a88ec3ebeb3bfcbf9ede51bc9e449 100644
--- a/pkg/front_end/lib/src/incremental/file_state.dart
+++ b/pkg/front_end/lib/src/incremental/file_state.dart
@@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
-import 'dart:convert';
import 'dart:typed_data';
import 'package:front_end/file_system.dart';
@@ -26,8 +25,7 @@ class FileState {
final Uri fileUri;
bool _exists;
- List<int> _contentBytes;
- String _content;
+ List<int> _content;
List<FileState> _importedFiles;
List<FileState> _exportedFiles;
@@ -38,10 +36,7 @@ class FileState {
FileState._(this._fsState, this.fileUri);
/// The content of the file.
- String get content => _content;
-
- /// The content bytes of the file.
- List<int> get contentBytes => _contentBytes;
+ List<int> get content => _content;
/// Whether the file exists.
bool get exists => _exists;
@@ -76,17 +71,15 @@ class FileState {
// Read the content.
try {
FileSystemEntity entry = _fsState.fileSystem.entityForUri(fileUri);
- _contentBytes = await entry.readAsBytes();
- _content = UTF8.decode(_contentBytes);
+ _content = await entry.readAsBytes();
_exists = true;
} catch (_) {
- _contentBytes = new Uint8List(0);
- _content = '';
+ _content = new Uint8List(0);
_exists = false;
}
// Parse directives.
- ScannerResult scannerResults = scanString(_content);
+ ScannerResult scannerResults = _scan();
var listener = new DirectiveListener();
new TopLevelParser(listener).parseUnit(scannerResults.tokens);
@@ -136,6 +129,13 @@ class FileState {
FileState file = await _fsState.getFile(resolvedUri);
files.add(file);
}
+
+ /// Scan the content of the file.
+ ScannerResult _scan() {
+ var zeroTerminatedBytes = new Uint8List(_content.length + 1);
+ zeroTerminatedBytes.setRange(0, _content.length, _content);
+ return scan(zeroTerminatedBytes);
+ }
}
/// Information about known file system state.
@@ -197,29 +197,23 @@ class _FileSystemViewEntry implements FileSystemEntity {
_FileSystemViewEntry(this.uri, this.file);
@override
- Future<bool> exists() async => file?.exists ?? false;
+ Future<bool> exists() async => _shouldNotBeQueried();
@override
- Future<DateTime> lastModified() async {
- throw new StateError(
- 'FileSystemViewEntry modification stamp should not be queried');
- }
+ Future<DateTime> lastModified() async => _shouldNotBeQueried();
@override
Future<List<int>> readAsBytes() async {
- _throwIfDoesNotExist();
- return file.contentBytes;
+ if (file == null) {
+ throw new FileSystemException(uri, 'File $uri does not exist.');
+ }
+ return file.content;
}
@override
- Future<String> readAsString() async {
- _throwIfDoesNotExist();
- return file.content;
- }
+ Future<String> readAsString() async => _shouldNotBeQueried();
- void _throwIfDoesNotExist() {
- if (file == null) {
- throw new FileSystemException(uri, 'File $uri does not exist.');
- }
+ dynamic _shouldNotBeQueried() {
+ throw new StateError('The method should not be invoked.');
Paul Berry 2017/05/09 12:38:21 Can we include a comment here so that in case some
scheglov 2017/05/09 16:20:08 Done.
}
}
« 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