From 6dc786b68369de4ba8227169172faeec94a32816 Mon Sep 17 00:00:00 2001 From: Shane32 Date: Mon, 4 Jul 2022 08:57:22 -0400 Subject: [PATCH 1/3] Define ParserContext as ref struct --- src/GraphQLParser.Tests/ParserTests.Throw.cs | 32 +++++++++++++++----- src/GraphQLParser/ParserContext.Parse.cs | 2 +- src/GraphQLParser/ParserContext.cs | 2 +- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/GraphQLParser.Tests/ParserTests.Throw.cs b/src/GraphQLParser.Tests/ParserTests.Throw.cs index 7f14addc..616da69e 100644 --- a/src/GraphQLParser.Tests/ParserTests.Throw.cs +++ b/src/GraphQLParser.Tests/ParserTests.Throw.cs @@ -294,20 +294,36 @@ public void Should_Throw_If_Descriptions_Not_Allowed(string query) [Fact] public void Should_Throw_On_Unknown_Cases_From_ExpectOneOf() { - var context = new ParserContext("abc", default); - Should.Throw(() => context.ParseNamedDefinition(new[] { "abc" })) + Should.Throw( + () => + { + var context = new ParserContext("abc", default); + context.ParseNamedDefinition(new[] { "abc" }); + }) .Message.ShouldBe("Unexpected keyword 'abc' in ParseNamedDefinition."); - context = new ParserContext("abc", default); - Should.Throw(() => context.ParseOperationType(new[] { "abc" })) + Should.Throw( + () => + { + var context = new ParserContext("abc", default); + context.ParseOperationType(new[] { "abc" }); + }) .Message.ShouldBe("Unexpected keyword 'abc' in ParseOperationType."); - context = new ParserContext("abc", default); - Should.Throw(() => context.ParseDirectiveLocation(new[] { "abc" })) + Should.Throw( + () => + { + var context = new ParserContext("abc", default); + context.ParseDirectiveLocation(new[] { "abc" }); + }) .Message.ShouldBe("Unexpected keyword 'abc' in ParseDirectiveLocation."); - context = new ParserContext("extend abc", default); - Should.Throw(() => context.ParseTypeExtension(new[] { "abc" })) + Should.Throw( + () => + { + var context = new ParserContext("extend abc", default); + context.ParseTypeExtension(new[] { "abc" }); + }) .Message.ShouldBe("Unexpected keyword 'abc' in ParseTypeExtension."); } } diff --git a/src/GraphQLParser/ParserContext.Parse.cs b/src/GraphQLParser/ParserContext.Parse.cs index 4a0cdad1..6e8a1622 100644 --- a/src/GraphQLParser/ParserContext.Parse.cs +++ b/src/GraphQLParser/ParserContext.Parse.cs @@ -4,7 +4,7 @@ namespace GraphQLParser; // WARNING: mutable struct, pass it by reference to those methods that will change it -internal partial struct ParserContext +internal ref partial struct ParserContext { // http://spec.graphql.org/October2021/#Document public GraphQLDocument ParseDocument() diff --git a/src/GraphQLParser/ParserContext.cs b/src/GraphQLParser/ParserContext.cs index 3a45135c..38c2f03c 100644 --- a/src/GraphQLParser/ParserContext.cs +++ b/src/GraphQLParser/ParserContext.cs @@ -6,7 +6,7 @@ namespace GraphQLParser; // WARNING: mutable struct, pass it by reference to those methods that will change it -internal partial struct ParserContext +internal ref partial struct ParserContext { private static string[] TopLevelKeywordOneOf { get; set; } = new[] { From b61ab22bbc1ac011213294a12d0d29f2af5231fe Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Tue, 5 Jul 2022 08:03:39 -0400 Subject: [PATCH 2/3] Update src/GraphQLParser/ParserContext.Parse.cs Co-authored-by: Ivan Maximov --- src/GraphQLParser/ParserContext.Parse.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GraphQLParser/ParserContext.Parse.cs b/src/GraphQLParser/ParserContext.Parse.cs index 6e8a1622..0cddc8f8 100644 --- a/src/GraphQLParser/ParserContext.Parse.cs +++ b/src/GraphQLParser/ParserContext.Parse.cs @@ -3,7 +3,7 @@ namespace GraphQLParser; -// WARNING: mutable struct, pass it by reference to those methods that will change it +// WARNING: mutable ref struct, pass it by reference to those methods that will change it internal ref partial struct ParserContext { // http://spec.graphql.org/October2021/#Document From a1c66af472741feb59765ef881deb8b335d8743b Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Tue, 5 Jul 2022 08:03:48 -0400 Subject: [PATCH 3/3] Update src/GraphQLParser/ParserContext.cs Co-authored-by: Ivan Maximov --- src/GraphQLParser/ParserContext.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/GraphQLParser/ParserContext.cs b/src/GraphQLParser/ParserContext.cs index 38c2f03c..e83c7a3c 100644 --- a/src/GraphQLParser/ParserContext.cs +++ b/src/GraphQLParser/ParserContext.cs @@ -5,7 +5,8 @@ namespace GraphQLParser; -// WARNING: mutable struct, pass it by reference to those methods that will change it +// WARNING: mutable ref struct, pass it by reference to those methods that will change it + internal ref partial struct ParserContext { private static string[] TopLevelKeywordOneOf { get; set; } = new[]