[PR #410] [MERGED] Optimized RendererBase #1003

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

📋 Pull Request Information

Original PR: https://github.com/xoofx/markdig/pull/410
Author: @KrisVandermotten
Created: 3/18/2020
Status: Merged
Merged: 3/23/2020
Merged by: @xoofx

Base: masterHead: RendererBase


📝 Commits (1)

📊 Changes

1 file changed (+34 additions, -38 deletions)

View changed files

📝 src/Markdig/Renderers/RendererBase.cs (+34 -38)

📄 Description

This PR contains a few small optimizations in RendererBase.

It uses some recent C# features, such as pattern matching, to make the code more readable.

It does not changes the semantics of the code. In fact, I believe that the Write(MarkdownObject obj) method contains abug, and this PR does not attempt to fix it.

To understand why there may be a bug here, consider this block of code:

if (!renderersPerType.TryGetValue(objectType, out renderer))
{
    for (int i = 0; i < ObjectRenderers.Count; i++)
    {
        var testRenderer = ObjectRenderers[i];
        if (testRenderer.Accept(this, obj))
        {
            renderersPerType[objectType] = renderer = testRenderer;
            break;
        }
    }
}

Notice how renderersPerType caches renderers based on the type of the MarkdownObject, whereas the IMarkdownObjectRenderer.Accept(RendererBase renderer, MarkdownObject obj) method takes an actual MarkdownObject as a parameter, not just its type.

The easiest fix would be to change that method signature. Unfortunately, renderers exist that test instance property values in that method, e.g. NormalizeAutoLinkRenderer.


🔄 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/410 **Author:** [@KrisVandermotten](https://github.com/KrisVandermotten) **Created:** 3/18/2020 **Status:** ✅ Merged **Merged:** 3/23/2020 **Merged by:** [@xoofx](https://github.com/xoofx) **Base:** `master` ← **Head:** `RendererBase` --- ### 📝 Commits (1) - [`1f3cf59`](https://github.com/xoofx/markdig/commit/1f3cf5962f441a2c2940ac9d1ecf26d70ac39e67) Optimized RendererBase ### 📊 Changes **1 file changed** (+34 additions, -38 deletions) <details> <summary>View changed files</summary> 📝 `src/Markdig/Renderers/RendererBase.cs` (+34 -38) </details> ### 📄 Description This PR contains a few small optimizations in `RendererBase`. It uses some recent C# features, such as pattern matching, to make the code more readable. It does not changes the semantics of the code. In fact, I believe that the `Write(MarkdownObject obj)` method contains abug, and this PR does not attempt to fix it. To understand why there may be a bug here, consider this block of code: if (!renderersPerType.TryGetValue(objectType, out renderer)) { for (int i = 0; i < ObjectRenderers.Count; i++) { var testRenderer = ObjectRenderers[i]; if (testRenderer.Accept(this, obj)) { renderersPerType[objectType] = renderer = testRenderer; break; } } } Notice how renderersPerType caches renderers based on the type of the MarkdownObject, whereas the `IMarkdownObjectRenderer.Accept(RendererBase renderer, MarkdownObject obj)` method takes an actual MarkdownObject as a parameter, not just its type. The easiest fix would be to change that method signature. Unfortunately, renderers exist that test instance property values in that method, e.g. `NormalizeAutoLinkRenderer`. --- <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:29 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#1003