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

Unified Diff: sdk/lib/convert/line_splitter.dart

Issue 1775683002: Make LineSplitter much faster for common case (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
« 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: sdk/lib/convert/line_splitter.dart
diff --git a/sdk/lib/convert/line_splitter.dart b/sdk/lib/convert/line_splitter.dart
index b5ec32bd6ee94bce6e248a2913cbf5c2e970991a..b9023f4c8fb246bfa235ef8c9e20ffa8120ac9c1 100644
--- a/sdk/lib/convert/line_splitter.dart
+++ b/sdk/lib/convert/line_splitter.dart
@@ -49,7 +49,29 @@ class LineSplitter extends Converter<String, List<String>> {
}
}
- List<String> convert(String data) => split(data).toList();
+ List<String> convert(String data) {
+ List<String> lines = <String>[];
+ int end = data.length;
+ int sliceStart = 0;
+ int char = 0;
+ for (int i = 0; i < end; i++) {
+ int previousChar = char;
+ char = data.codeUnitAt(i);
+ if (char != _CR) {
+ if (char != _LF) continue;
+ if (previousChar == _CR) {
+ sliceStart = i + 1;
+ continue;
+ }
+ }
+ lines.add(data.substring(sliceStart, i));
+ sliceStart = i + 1;
+ }
+ if (sliceStart < end) {
+ lines.add(data.substring(sliceStart, end));
+ }
+ return lines;
+ }
StringConversionSink startChunkedConversion(Sink<String> sink) {
if (sink is! StringConversionSink) {
« 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