Skip to content

Commit

Permalink
Optimized MimeParser.IsMboxMarker() - noticeably improves performance
Browse files Browse the repository at this point in the history
Apparently fixed statements are quite expensive.
  • Loading branch information
jstedfast committed Sep 17, 2013
1 parent fdd4727 commit a6384b0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions MimeKit/MimeParser.cs
Expand Up @@ -320,9 +320,9 @@ static unsafe bool CStringsEqual (byte* str1, byte* str2, int length)

static unsafe bool IsMboxMarker (byte* text)
{
fixed (byte* mbox = Boundary.MboxFrom) {
return CStringsEqual (text, mbox, 5);
}
byte* inptr = text;

return *inptr++ == (byte) 'F' && *inptr++ == (byte) 'r' && *inptr++ == (byte) 'o' && *inptr++ == (byte) 'm' && *inptr == (byte) ' ';
}

unsafe int StepMboxMarker ()
Expand Down Expand Up @@ -686,13 +686,13 @@ static unsafe bool IsBoundary (byte* text, int length, byte[] boundary, int boun
if (boundaryLength > length)
return false;

fixed (byte* boundaryptr = boundary, from = Boundary.MboxFrom) {
fixed (byte* boundaryptr = boundary) {
// make sure that the text matches the boundary
if (!CStringsEqual (text, boundaryptr, boundaryLength))
return false;

// if this is an mbox marker, we're done
if (CStringsEqual (text, from, 5))
if (IsMboxMarker (text))
return true;

// the boundary may optionally be followed by lwsp
Expand Down

0 comments on commit a6384b0

Please sign in to comment.