[PR #399] [MERGED] Some optimizations in StringLineGroup #996

Closed
opened 2026-01-29 14:48:21 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/xoofx/markdig/pull/399
Author: @KrisVandermotten
Created: 2/15/2020
Status: Merged
Merged: 2/18/2020
Merged by: @xoofx

Base: masterHead: StringLineGroup


📝 Commits (1)

  • 7d61df2 Some optimizations in StringLineGroup

📊 Changes

1 file changed (+17 additions, -29 deletions)

View changed files

📝 src/Markdig/Helpers/StringLineGroup.cs (+17 -29)

📄 Description

This PR contributes a few improvements to StringLineGroup.

RemoveAt(int)

A memory leak was fixed and code duplication reduced.

ToSlice(List<LineOffset>)

First, the case where Count == 1 has been moved before the case where Count == 0, simply because it is so much more common. Indeed, out of 1023 unit tests that call this method, 872 execute the Count == 1 branch, but none of them execute the Count == 0 branch.

Secondly, the loop was restructured to simplify it and reduce code duplication. Using ref var line = ref Lines[i];, the Lines array is indexed only once per iteration.

Iterator.NextChar()

_offset++; has been moved into the if branch, so that the _offset--; in the else branch can be removed.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/xoofx/markdig/pull/399 **Author:** [@KrisVandermotten](https://github.com/KrisVandermotten) **Created:** 2/15/2020 **Status:** ✅ Merged **Merged:** 2/18/2020 **Merged by:** [@xoofx](https://github.com/xoofx) **Base:** `master` ← **Head:** `StringLineGroup` --- ### 📝 Commits (1) - [`7d61df2`](https://github.com/xoofx/markdig/commit/7d61df2c0c35981d7d1ad575b43b509be1bb0ce7) Some optimizations in StringLineGroup ### 📊 Changes **1 file changed** (+17 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `src/Markdig/Helpers/StringLineGroup.cs` (+17 -29) </details> ### 📄 Description This PR contributes a few improvements to `StringLineGroup`. #### `RemoveAt(int)` A memory leak was fixed and code duplication reduced. #### `ToSlice(List<LineOffset>)` First, the case where `Count == 1` has been moved before the case where `Count == 0`, simply because it is so much more common. Indeed, out of 1023 unit tests that call this method, 872 execute the `Count == 1` branch, but none of them execute the `Count == 0` branch. Secondly, the loop was restructured to simplify it and reduce code duplication. Using `ref var line = ref Lines[i];`, the `Lines` array is indexed only once per iteration. #### `Iterator.NextChar()` `_offset++;` has been moved into the `if` branch, so that the `_offset--;` in the else branch can be removed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 14:48:21 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#996