Fix bug where appending to a nested block list before an outdented sibling failed - #2482
Fix bug where appending to a nested block list before an outdented sibling failed#2482slashblog wants to merge 9 commits into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request updates the block list appending logic in yaml_edit to trim trailing whitespace when finding the next newline index. The reviewer identified a performance issue where creating a substring on every append operation leads to O(N) time and memory complexity, as well as a potential RangeError crash if the index becomes negative. An optimized O(1) auxiliary space solution was suggested to scan backwards instead.
|
Thanks for investigating and finding the cause of #2481! Instead of manually backtracking whitespace characters with a We can simplify if (list.isNotEmpty) {
final lastValueSpanEnd = getContentSensitiveEnd(list.nodes.last);
final nextNewLineIndex = yaml.indexOf('\n', lastValueSpanEnd);
if (nextNewLineIndex == -1) {
formattedValue = getLineEnding(yaml) + formattedValue;
} else {
offset = nextNewLineIndex + 1;
}
}Could you also:
|
|
@sigurdm Done changes as per your comment. |
|
Please update the PR title to say what the change does, rather than repeat the issue number |
|
@sigurdm I have changed both PR title and Changelog entry. Please do the needful. |
Contribution guidelines:
dart format.Many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.
Note: The Dart team is trialing Gemini Code Assist. Don't take its comments as final Dart team feedback. Use the suggestions if they're helpful; otherwise, wait for a human reviewer.