mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-09 13:56:56 +00:00
[PR #288] [MERGED] Rewrite Descendants iteratively #920
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/xoofx/markdig/pull/288
Author: @MihaZupan
Created: 1/18/2019
Status: ✅ Merged
Merged: 1/19/2019
Merged by: @xoofx
Base:
master← Head:rewrite-descendants-search📝 Commits (7)
1bbe20dRewrite Descendants(MarkdownObject) iteratively37325f1Use existing Descantants(ContainerInline) implementation4519d38Rewrite Descendants(ContainerBlock) iteratively282da04Rewrite Descendants(ContainerInline) iterativelyf1b736fAdd Test for Descendants orderb2a542bSimplify push condition95cbf0eCache Schema markdown in Tests📊 Changes
5 files changed (+248 additions, -147 deletions)
View changed files
📝
src/Markdig.Tests/Markdig.Tests.csproj(+1 -0)➕
src/Markdig.Tests/TestDescendantsOrder.cs(+85 -0)📝
src/Markdig.Tests/TestParser.cs(+16 -0)📝
src/Markdig/Syntax/Inlines/ContainerInline.cs(+28 -17)📝
src/Markdig/Syntax/MarkdownObjectExtensions.cs(+118 -130)📄 Description
I rewrote the
Descendantsextension methods to eliminate recursion. The order of returned elements is kept the same.This comes with a significant memory allocation reduction when using
Descendantsover the entire AST like I do in my project.Benchmarking between the recursive and iterative approaches I get this:
Iterative:
Recursive:
Where
Markdigis only parsing to the AST whileMarkdig_Descendantsparses to AST and loops over descendants once.I have tested that the order is not modified when calling descending anywhere in the test suite.
I don't have tests for
Descendants<T>ofContainerInlineandContainerBlockas they appear to not be used anywhere in Markdig itself, but I have included iterative implementations for those as well.In the future, a few bytes could be shaved off by using ValueTuple instead of two stacks.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.