Skip to content

Conversation

@prozolic
Copy link
Contributor

This PR replace Dictionary.TryAdd instead of ContainsKey and indexer by reducing lookups.

Copilot AI review requested due to automatic review settings November 28, 2025 23:58
Copilot finished reviewing on behalf of prozolic November 29, 2025 00:00
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves performance by replacing the ContainsKey + indexer pattern with the more efficient Dictionary.TryAdd method, which reduces dictionary lookups from two operations to one. A polyfill implementation is provided for older frameworks that don't have native TryAdd support.

Key Changes:

  • Added a polyfill DictionaryExtensions.TryAdd for frameworks prior to .NET Standard 2.1
  • Replaced ContainsKey + indexer pattern with TryAdd in three locations
  • Reduced dictionary lookup operations for better performance

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/Markdig/Polyfills/DictionaryExtensions.cs Adds TryAdd polyfill for older .NET frameworks
src/Markdig/Syntax/LinkReferenceDefinitionGroup.cs Uses TryAdd in Set method to reduce lookups
src/Markdig/Parsers/ParserList.cs Uses TryAdd when counting opening characters
src/Markdig/Helpers/CharacterMap.cs Uses TryAdd when building non-ASCII character map

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants