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 Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
base64_test.dart [tests] Fix CompileTimeErrors in migrated tests. 2020-04-13 22:42:51 +00:00
chunked_conversion1_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
chunked_conversion2_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
chunked_conversion_json_decode1_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
chunked_conversion_json_encode1_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
chunked_conversion_utf8_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
chunked_conversion_utf82_test.dart Adjust UTF-8 tests to match WHATWG standard expectations. 2020-05-04 10:48:32 +00:00
chunked_conversion_utf83_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
chunked_conversion_utf84_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
chunked_conversion_utf85_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
chunked_conversion_utf86_test.dart Adjust UTF-8 tests to match WHATWG standard expectations. 2020-05-04 10:48:32 +00:00
chunked_conversion_utf87_test.dart Adjust UTF-8 tests to match WHATWG standard expectations. 2020-05-04 10:48:32 +00:00
chunked_conversion_utf88_test.dart Adjust UTF-8 tests to match WHATWG standard expectations. 2020-05-04 10:48:32 +00:00
chunked_conversion_utf89_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
close_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
codec1_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
codec2_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
encoding_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
html_escape_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
json_chunk_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
json_lib_test.dart [tests] Fix CompileTimeErrors in migrated tests. 2020-04-13 22:42:51 +00:00
json_pretty_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
json_test.dart Spelling tests 2022-12-19 12:56:47 +00:00
json_toEncodable_reviver_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
json_unicode_tests.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
json_utf8_chunk_test.dart Adjust UTF-8 tests to match WHATWG standard expectations. 2020-05-04 10:48:32 +00:00
json_utf8_test.dart Fix null-safety migration bug in VM version of fuse JSON-UTF-8 decoder. 2021-06-07 11:43:02 +00:00
json_util_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
latin1_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
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 Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
streamed_conversion_json_encode1_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
streamed_conversion_json_utf8_decode_test.dart [vm] Alternate fix for mismatch between native and intrinsic versions of writeIntoOneByteString. 2022-01-21 19:32:40 +00:00
streamed_conversion_json_utf8_encode_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
streamed_conversion_utf8_decode_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
streamed_conversion_utf8_encode_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
unicode_tests.dart [tests] Fix CompileTimeErrors in migrated tests. 2020-04-13 22:42:51 +00:00
utf8_encode_test.dart Adjust UTF-8 tests to match WHATWG standard expectations. 2020-05-04 10:48:32 +00:00
utf8_test.dart Adjust UTF-8 tests to match WHATWG standard expectations. 2020-05-04 10:48:32 +00:00
utf82_test.dart Adjust UTF-8 tests to match WHATWG standard expectations. 2020-05-04 10:48:32 +00:00
utf83_test.dart Migrate tests/lib_2/convert -> tests/lib/convert. 2020-01-16 17:46:02 +00:00
utf84_test.dart Adjust UTF-8 tests to match WHATWG standard expectations. 2020-05-04 10:48:32 +00:00
utf85_test.dart Adjust UTF-8 tests to match WHATWG standard expectations. 2020-05-04 10:48:32 +00:00