Fix for #91 - Turn some commonly allocated types into structs

These types are allocated for every state transition in the parser (State)
or every character that's read (character reference) and are fairly
compact. Turning them into structs will remove a significant number of unnecessary
allocations in the parser.

For our razor code generation benchmark, making these changes yields about
500-750ms of speedup (out of 40000ms) or about 1%.
This commit is contained in:
Ryan Nowak 2014-09-11 12:54:02 -07:00
parent 102e2e5739
commit 2d9b3dd4fb
1 changed files with 8 additions and 5 deletions

View File

@ -114,16 +114,19 @@ namespace Microsoft.AspNet.Razor.Text
return null;
}
internal class CharacterReference
internal struct CharacterReference
{
private readonly char _character;
private readonly SourceLocation _location;
public CharacterReference(char character, SourceLocation location)
{
Character = character;
Location = location;
_character = character;
_location = location;
}
public char Character { get; private set; }
public SourceLocation Location { get; private set; }
public char Character { get { return _character; } }
public SourceLocation Location { get { return _location; } }
}
private class TextLine