dart-sdk/tests/lib_2
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
..
analyzer Normalize status files 2019-06-19 23:04:01 +00:00
async Spelling tests 2023-01-19 16:24:29 +00:00
collection [lib/collection] Test for #48282 2022-02-08 19:36:38 +00:00
convert Optimize LineSplitter. 2023-02-21 11:33:24 +00:00
developer Don't mutate argument to dart:developer's postEvent. 2022-12-22 23:10:13 +00:00
html Update CFE expectations and fix top-level external members 2023-01-16 22:31:33 +00:00
isolate Spelling tests 2023-01-19 16:24:29 +00:00
js [dart2js] Ensure JavaScriptObject's interceptor is emitted. 2023-02-13 20:35:59 +00:00
math Spelling tests 2023-01-19 16:24:29 +00:00
mirrors [tests] Fix lib/mirrors/reflected_type_generics_test/01 2023-01-18 22:35:38 +00:00
typed_data [vm] Add unmodifiable typed data as a type that can be sent with Dart_PostCObject. 2022-09-12 19:45:12 +00:00
web Add language versions to _2 test libraries 2021-04-26 17:58:57 +00:00
lib_2.status [test_runner] Add new name for ddc compiler 2023-02-09 18:32:58 +00:00
lib_2_app_jit.status Remove appJit and precompiled compiler options 2019-06-24 16:07:27 +00:00
lib_2_dart2js.status [test] Skip html/interactive_geolocation_test on all OSs 2023-02-17 19:35:32 +00:00
lib_2_dartdevc.status [test] Skip html/interactive_geolocation_test on all OSs 2023-02-17 19:35:32 +00:00
lib_2_kernel.status [gardening] Mark all tests as slow in debug-ia32 mode 2022-07-21 10:22:45 +00:00
lib_2_precompiled.status [testing] Remove --compiler=none from test.py 2022-10-19 08:09:58 +00:00
lib_2_vm.status [test] Inform status files about the new simulated architectures. 2022-02-03 20:32:16 +00:00