Skip to content

Commit

Permalink
Avoid allocations in EntityHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan committed Apr 4, 2020
1 parent 5e1c162 commit b090f24
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 254 deletions.
3 changes: 2 additions & 1 deletion src/Markdig/Extensions/Abbreviations/AbbreviationParser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Alexandre Mutel. All rights reserved.
// This file is licensed under the BSD-Clause 2 license.
// See the license.txt file in the project root for more information.
using System;
using System.Collections.Generic;
using Markdig.Helpers;
using Markdig.Parsers;
Expand Down Expand Up @@ -115,7 +116,7 @@ private void DocumentOnProcessInlinesBegin(InlineProcessor inlineProcessor, Inli

ValidAbbreviationStart:;

if (prefixTree.TryMatchLongest(text, i, content.End - i + 1, out KeyValuePair<string, Abbreviation> abbreviationMatch))
if (prefixTree.TryMatchLongest(text.AsSpan(i, content.End - i + 1), out KeyValuePair<string, Abbreviation> abbreviationMatch))
{
var match = abbreviationMatch.Key;
if (!IsValidAbbreviationEnding(match, content, i))
Expand Down
3 changes: 2 additions & 1 deletion src/Markdig/Extensions/Emoji/EmojiParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// This file is licensed under the BSD-Clause 2 license.
// See the license.txt file in the project root for more information.

using System;
using System.Collections.Generic;
using Markdig.Helpers;
using Markdig.Parsers;
Expand Down Expand Up @@ -34,7 +35,7 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice)
}

// Try to match an emoji shortcode or smiley
if (!_emojiMapping.PrefixTree.TryMatchLongest(slice.Text, slice.Start, slice.Length, out KeyValuePair<string, string> match))
if (!_emojiMapping.PrefixTree.TryMatchLongest(slice.Text.AsSpan(slice.Start, slice.Length), out KeyValuePair<string, string> match))
{
return false;
}
Expand Down
6 changes: 5 additions & 1 deletion src/Markdig/Helpers/CharHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,11 @@ public static bool IsLowSurrogate(char c)

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsInInclusiveRange(char c, char min, char max)
=> (uint) (c - min) <= (uint) (max - min);
=> (uint)(c - min) <= (uint)(max - min);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static bool IsInInclusiveRange(int value, uint min, uint max)
=> ((uint)value - min) <= (max - min);

public static IEnumerable<int> ToUtf32(StringSlice text)
{
Expand Down
Loading

0 comments on commit b090f24

Please sign in to comment.