From 2d9b3dd4fb0d09f9b992e2a14a77ddb91cb9a455 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Thu, 11 Sep 2014 12:54:02 -0700 Subject: [PATCH] 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%. --- .../Text/LineTrackingStringBuffer.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNet.Razor/Text/LineTrackingStringBuffer.cs b/src/Microsoft.AspNet.Razor/Text/LineTrackingStringBuffer.cs index 938b0f0ad3..862903dd0c 100644 --- a/src/Microsoft.AspNet.Razor/Text/LineTrackingStringBuffer.cs +++ b/src/Microsoft.AspNet.Razor/Text/LineTrackingStringBuffer.cs @@ -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