dart-sdk/tests/lib/convert
Lasse R.H. Nielsen 164f8588d6 Optimize LineSplitter.
Avoid quadratic behavior when multiple chunks fail to
have a line break, and the carry-over string gets repeatedly extended.

In the original chunked conversion code, the chunk handling code retained the trailing, non-line-terminated text of the previous chunk, then eagerly concatenated it with the next chunk in order to continue looking for lines. That's moderately effective when lines are shorter than chunks, and neither are too large.
However, a very long line spread across many chunks would perform repeated string concatenation with quadratic time complexity.

This change gives `LineSplitter` the option of using a `StringBuffer` to collect multiple carry-over line parts.
The buffer is needed whenever a chunk does not contain a line break, and needs to be combined with a previous chunk's carry-over. This avoids ever directly concatenating any more than two strings.
The `StringBuffer` is not allocated until it's first needed, so if lines are generally shorter than chunks, the buffer won't be used. Once allocated, the buffer is retained in case a buffer will be needed again, but cleared when its contents are used.

The code optimizes for the simple case of each chunk having a line break.

Fixes #51167

Bug: https://github.com/dart-lang/sdk/issues/51167
Change-Id: I600a011e02aa9f1ad6f88e45764df5b2e8eccfa3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280100
Reviewed-by: Leaf Petersen <leafp@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-02-21 11:33:24 +00:00
..
ascii_test.dart
base64_test.dart
chunked_conversion1_test.dart
chunked_conversion2_test.dart
chunked_conversion_json_decode1_test.dart
chunked_conversion_json_encode1_test.dart
chunked_conversion_utf8_test.dart
chunked_conversion_utf82_test.dart
chunked_conversion_utf83_test.dart
chunked_conversion_utf84_test.dart
chunked_conversion_utf85_test.dart
chunked_conversion_utf86_test.dart
chunked_conversion_utf87_test.dart
chunked_conversion_utf88_test.dart
chunked_conversion_utf89_test.dart
close_test.dart
codec1_test.dart
codec2_test.dart
encoding_test.dart
html_escape_test.dart
json_chunk_test.dart
json_lib_test.dart
json_pretty_test.dart
json_test.dart Spelling tests 2022-12-19 12:56:47 +00:00
json_toEncodable_reviver_test.dart
json_unicode_tests.dart
json_utf8_chunk_test.dart
json_utf8_test.dart
json_util_test.dart
latin1_test.dart
line_splitter_performance_test.dart Optimize LineSplitter. 2023-02-21 11:33:24 +00:00
line_splitter_test.dart Optimize LineSplitter. 2023-02-21 11:33:24 +00:00
streamed_conversion_json_decode1_test.dart
streamed_conversion_json_encode1_test.dart
streamed_conversion_json_utf8_decode_test.dart
streamed_conversion_json_utf8_encode_test.dart
streamed_conversion_utf8_decode_test.dart
streamed_conversion_utf8_encode_test.dart
unicode_tests.dart
utf8_encode_test.dart
utf8_test.dart
utf82_test.dart
utf83_test.dart
utf84_test.dart
utf85_test.dart