forked from xoofx/markdig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Benchmarks] Enable ImplictUsings and use file-scoped namespaces
- Loading branch information
Showing
5 changed files
with
178 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,38 @@ | ||
// Copyright (c) Alexandre Mutel. All rights reserved. | ||
// 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.Runtime.InteropServices; | ||
using System.Text; | ||
|
||
namespace Testamina.Markdig.Benchmarks | ||
namespace Testamina.Markdig.Benchmarks; | ||
|
||
public static class CommonMarkLib | ||
{ | ||
public static class CommonMarkLib | ||
public static string ToHtml(string text) | ||
{ | ||
public static string ToHtml(string text) | ||
unsafe | ||
{ | ||
unsafe | ||
{ | ||
var textAsArray = Encoding.UTF8.GetBytes(text); | ||
var textAsArray = Encoding.UTF8.GetBytes(text); | ||
|
||
fixed (void* ptext = textAsArray) | ||
fixed (void* ptext = textAsArray) | ||
{ | ||
var ptr = (byte*)cmark_markdown_to_html(new IntPtr(ptext), text.Length); | ||
int length = 0; | ||
while (ptr[length] != 0) | ||
{ | ||
var ptr = (byte*)cmark_markdown_to_html(new IntPtr(ptext), text.Length); | ||
int length = 0; | ||
while (ptr[length] != 0) | ||
{ | ||
length++; | ||
} | ||
var buffer = new byte[length]; | ||
Marshal.Copy(new IntPtr(ptr), buffer, 0, length); | ||
var result = Encoding.UTF8.GetString(buffer); | ||
Marshal.FreeHGlobal(new IntPtr(ptr)); | ||
return result; | ||
length++; | ||
} | ||
var buffer = new byte[length]; | ||
Marshal.Copy(new IntPtr(ptr), buffer, 0, length); | ||
var result = Encoding.UTF8.GetString(buffer); | ||
Marshal.FreeHGlobal(new IntPtr(ptr)); | ||
return result; | ||
} | ||
} | ||
|
||
// char *cmark_markdown_to_html(const char *text, size_t len, int options); | ||
[DllImport("cmark", CallingConvention = CallingConvention.Cdecl)] | ||
private static extern IntPtr cmark_markdown_to_html(IntPtr charBuffer, int len, int options = 0); | ||
} | ||
|
||
// char *cmark_markdown_to_html(const char *text, size_t len, int options); | ||
[DllImport("cmark", CallingConvention = CallingConvention.Cdecl)] | ||
private static extern IntPtr cmark_markdown_to_html(IntPtr charBuffer, int len, int options = 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.