From 5a6f71832f0f017d59996d89653a4fc1cb6eb8e5 Mon Sep 17 00:00:00 2001 From: mdesalvo Date: Mon, 18 Mar 2019 20:51:13 +0100 Subject: [PATCH] Little optimization to ToString() of queries --- RDFSharp/Query/Queries/Ask/RDFAskQuery.cs | 6 ++-- .../Queries/Construct/RDFConstructQuery.cs | 21 ++++++++------ .../Queries/Describe/RDFDescribeQuery.cs | 21 ++++++++------ .../Query/Queries/Select/RDFSelectQuery.cs | 29 ++++++++++--------- 4 files changed, 43 insertions(+), 34 deletions(-) diff --git a/RDFSharp/Query/Queries/Ask/RDFAskQuery.cs b/RDFSharp/Query/Queries/Ask/RDFAskQuery.cs index e8484f1a..473f06e2 100644 --- a/RDFSharp/Query/Queries/Ask/RDFAskQuery.cs +++ b/RDFSharp/Query/Queries/Ask/RDFAskQuery.cs @@ -16,7 +16,6 @@ limitations under the License. using System; using System.Collections.Generic; -using System.Data; using System.IO; using System.Linq; using System.Net; @@ -69,8 +68,9 @@ public override String ToString() #region EVALUABLEMEMBERS Boolean printingUnion = false; - RDFQueryMember lastQueryMbr = this.GetEvaluableQueryMembers().LastOrDefault(); - foreach (var queryMember in this.GetEvaluableQueryMembers()) + List evaluableQueryMembers = this.GetEvaluableQueryMembers().ToList(); + RDFQueryMember lastQueryMbr = evaluableQueryMembers.LastOrDefault(); + foreach (var queryMember in evaluableQueryMembers) { #region PATTERNGROUPS diff --git a/RDFSharp/Query/Queries/Construct/RDFConstructQuery.cs b/RDFSharp/Query/Queries/Construct/RDFConstructQuery.cs index 31ae2bda..2b96365d 100644 --- a/RDFSharp/Query/Queries/Construct/RDFConstructQuery.cs +++ b/RDFSharp/Query/Queries/Construct/RDFConstructQuery.cs @@ -108,8 +108,9 @@ public override String ToString() #region EVALUABLEMEMBERS Boolean printingUnion = false; - RDFQueryMember lastQueryMbr = this.GetEvaluableQueryMembers().LastOrDefault(); - foreach (var queryMember in this.GetEvaluableQueryMembers()) + List evaluableQueryMembers = this.GetEvaluableQueryMembers().ToList(); + RDFQueryMember lastQueryMbr = evaluableQueryMembers.LastOrDefault(); + foreach (var queryMember in evaluableQueryMembers) { #region PATTERNGROUPS @@ -176,15 +177,17 @@ public override String ToString() #endregion #region MODIFIERS + List modifiers = this.GetModifiers().ToList(); + // LIMIT/OFFSET - if (this.GetModifiers().Any(mod => mod is RDFLimitModifier || mod is RDFOffsetModifier)) + if (modifiers.Any(mod => mod is RDFLimitModifier || mod is RDFOffsetModifier)) { - this.GetModifiers().Where(mod => mod is RDFLimitModifier) - .ToList() - .ForEach(lim => query.Append("\n" + lim)); - this.GetModifiers().Where(mod => mod is RDFOffsetModifier) - .ToList() - .ForEach(off => query.Append("\n" + off)); + modifiers.Where(mod => mod is RDFLimitModifier) + .ToList() + .ForEach(lim => query.Append("\n" + lim)); + modifiers.Where(mod => mod is RDFOffsetModifier) + .ToList() + .ForEach(off => query.Append("\n" + off)); } #endregion diff --git a/RDFSharp/Query/Queries/Describe/RDFDescribeQuery.cs b/RDFSharp/Query/Queries/Describe/RDFDescribeQuery.cs index 1fab7270..b2fbdee5 100644 --- a/RDFSharp/Query/Queries/Describe/RDFDescribeQuery.cs +++ b/RDFSharp/Query/Queries/Describe/RDFDescribeQuery.cs @@ -96,8 +96,9 @@ public override String ToString() #region EVALUABLEMEMBERS Boolean printingUnion = false; - RDFQueryMember lastQueryMbr = this.GetEvaluableQueryMembers().LastOrDefault(); - foreach (var queryMember in this.GetEvaluableQueryMembers()) + List evaluableQueryMembers = this.GetEvaluableQueryMembers().ToList(); + RDFQueryMember lastQueryMbr = evaluableQueryMembers.LastOrDefault(); + foreach (var queryMember in evaluableQueryMembers) { #region PATTERNGROUPS @@ -164,15 +165,17 @@ public override String ToString() #endregion #region MODIFIERS + List modifiers = this.GetModifiers().ToList(); + // LIMIT/OFFSET - if (this.GetModifiers().Any(mod => mod is RDFLimitModifier || mod is RDFOffsetModifier)) + if (modifiers.Any(mod => mod is RDFLimitModifier || mod is RDFOffsetModifier)) { - this.GetModifiers().Where(mod => mod is RDFLimitModifier) - .ToList() - .ForEach(lim => query.Append("\n" + lim)); - this.GetModifiers().Where(mod => mod is RDFOffsetModifier) - .ToList() - .ForEach(off => query.Append("\n" + off)); + modifiers.Where(mod => mod is RDFLimitModifier) + .ToList() + .ForEach(lim => query.Append("\n" + lim)); + modifiers.Where(mod => mod is RDFOffsetModifier) + .ToList() + .ForEach(off => query.Append("\n" + off)); } #endregion diff --git a/RDFSharp/Query/Queries/Select/RDFSelectQuery.cs b/RDFSharp/Query/Queries/Select/RDFSelectQuery.cs index 6fb243d1..2cc6107a 100644 --- a/RDFSharp/Query/Queries/Select/RDFSelectQuery.cs +++ b/RDFSharp/Query/Queries/Select/RDFSelectQuery.cs @@ -96,8 +96,9 @@ public override String ToString() #region EVALUABLEMEMBERS Boolean printingUnion = false; - RDFQueryMember lastQueryMbr = this.GetEvaluableQueryMembers().LastOrDefault(); - foreach (var queryMember in this.GetEvaluableQueryMembers()) + List evaluableQueryMembers = this.GetEvaluableQueryMembers().ToList(); + RDFQueryMember lastQueryMbr = evaluableQueryMembers.LastOrDefault(); + foreach (var queryMember in evaluableQueryMembers) { #region PATTERNGROUPS @@ -164,24 +165,26 @@ public override String ToString() #endregion #region MODIFIERS + List modifiers = this.GetModifiers().ToList(); + // ORDER BY - if (this.GetModifiers().Any(mod => mod is RDFOrderByModifier)) + if (modifiers.Any(mod => mod is RDFOrderByModifier)) { query.Append("\nORDER BY"); - this.GetModifiers().Where(mod => mod is RDFOrderByModifier) - .ToList() - .ForEach(om => query.Append(" " + om)); + modifiers.Where(mod => mod is RDFOrderByModifier) + .ToList() + .ForEach(om => query.Append(" " + om)); } // LIMIT/OFFSET - if (this.GetModifiers().Any(mod => mod is RDFLimitModifier || mod is RDFOffsetModifier)) + if (modifiers.Any(mod => mod is RDFLimitModifier || mod is RDFOffsetModifier)) { - this.GetModifiers().Where(mod => mod is RDFLimitModifier) - .ToList() - .ForEach(lim => query.Append("\n" + lim)); - this.GetModifiers().Where(mod => mod is RDFOffsetModifier) - .ToList() - .ForEach(off => query.Append("\n" + off)); + modifiers.Where(mod => mod is RDFLimitModifier) + .ToList() + .ForEach(lim => query.Append("\n" + lim)); + modifiers.Where(mod => mod is RDFOffsetModifier) + .ToList() + .ForEach(off => query.Append("\n" + off)); } #endregion