Skip to content

Commit

Permalink
Modified Rfc2047.cs to specify initial capacities for List<Token>
Browse files Browse the repository at this point in the history
Based on testing, 16 tokens covers > ~50% of cases and 32 tokens covers
another ~25%. Very few needed more than 128.
  • Loading branch information
jstedfast committed Aug 27, 2023
1 parent df39eb2 commit 58c1625
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions MimeKit/Utils/Rfc2047.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ namespace MimeKit.Utils {
/// </remarks>
public static class Rfc2047
{
const int PhraseTokenCapacity = 16;
const int TextTokenCapacity = 32;

class Token {
public ContentEncoding Encoding;
public string CharsetName;
Expand Down Expand Up @@ -195,9 +198,9 @@ static unsafe bool TryGetEncodedWordToken (byte* input, byte* word, int length,

static unsafe List<Token> TokenizePhrase (ParserOptions options, byte* inbuf, int startIndex, int length)
{
var tokens = new List<Token> (PhraseTokenCapacity);
byte* text, word, inptr = inbuf + startIndex;
byte* inend = inptr + length;
var tokens = new List<Token> ();
bool encoded = false;
Token token = null;
Token lwsp = null;
Expand Down Expand Up @@ -325,9 +328,9 @@ static unsafe List<Token> TokenizePhrase (ParserOptions options, byte* inbuf, in

static unsafe List<Token> TokenizeText (ParserOptions options, byte* inbuf, int startIndex, int length)
{
var tokens = new List<Token> (TextTokenCapacity);
byte* text, word, inptr = inbuf + startIndex;
byte* inend = inptr + length;
var tokens = new List<Token> ();
bool encoded = false;
Token token = null;
Token lwsp = null;
Expand Down

0 comments on commit 58c1625

Please sign in to comment.