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

Unified Diff: pkg/compiler/lib/src/scanner/utf8_bytes_scanner.dart

Issue 992333003: dart2js: Handle zero-terminated content explicitly. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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: pkg/compiler/lib/src/scanner/utf8_bytes_scanner.dart
diff --git a/pkg/compiler/lib/src/scanner/utf8_bytes_scanner.dart b/pkg/compiler/lib/src/scanner/utf8_bytes_scanner.dart
index c2adeb41672d726ff10b7d4a3a8c3f31a7cc0189..d919596154580c9a6e09b6a710dfafb7142d9544 100644
--- a/pkg/compiler/lib/src/scanner/utf8_bytes_scanner.dart
+++ b/pkg/compiler/lib/src/scanner/utf8_bytes_scanner.dart
@@ -9,7 +9,11 @@ part of scanner;
* that points to substrings.
*/
class Utf8BytesScanner extends ArrayBasedScanner {
- /** The file content. */
+ /**
+ * The file content.
+ *
+ * The content is zero-terminated.
+ */
List<int> bytes;
/**
@@ -66,9 +70,9 @@ class Utf8BytesScanner extends ArrayBasedScanner {
* is not the case, the entire array is copied before scanning.
*/
Utf8BytesScanner(SourceFile file, {bool includeComments: false})
- : bytes = file.slowUtf8Bytes(),
+ : bytes = file.slowUtf8ZeroTerminatedBytes(),
super(file, includeComments) {
- ensureZeroTermination();
+ assert(bytes.last == 0);
// Skip a leading BOM.
if (_containsBomAt(0)) byteOffset += 3;
}
@@ -80,21 +84,11 @@ class Utf8BytesScanner extends ArrayBasedScanner {
* the file. If this is not the case, the entire array is copied before
* scanning.
*/
- Utf8BytesScanner.fromBytes(this.bytes, {bool includeComments: false})
- : super(null, includeComments) {
- ensureZeroTermination();
- }
-
- void ensureZeroTermination() {
- if (bytes.isEmpty || bytes[bytes.length - 1] != 0) {
- // TODO(lry): abort instead of copying the array, or warn?
- var newBytes = new Uint8List(bytes.length + 1);
- for (int i = 0; i < bytes.length; i++) {
- newBytes[i] = bytes[i];
- }
- newBytes[bytes.length] = 0;
- bytes = newBytes;
- }
+ Utf8BytesScanner.fromBytes(List<int> zeroTerminatedBytes,
+ {bool includeComments: false})
+ : this.bytes = zeroTerminatedBytes,
+ super(null, includeComments) {
+ assert(bytes.last == 0);
}
bool _containsBomAt(int offset) {

Powered by Google App Engine
This is Rietveld 408576698