Skip to content

Commit

Permalink
Little optimization to ToString() of queries
Browse files Browse the repository at this point in the history
  • Loading branch information
mdesalvo committed Mar 18, 2019
1 parent 6196b2e commit 5a6f718
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 34 deletions.
6 changes: 3 additions & 3 deletions RDFSharp/Query/Queries/Ask/RDFAskQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<RDFQueryMember> evaluableQueryMembers = this.GetEvaluableQueryMembers().ToList();
RDFQueryMember lastQueryMbr = evaluableQueryMembers.LastOrDefault();
foreach (var queryMember in evaluableQueryMembers)
{

#region PATTERNGROUPS
Expand Down
21 changes: 12 additions & 9 deletions RDFSharp/Query/Queries/Construct/RDFConstructQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RDFQueryMember> evaluableQueryMembers = this.GetEvaluableQueryMembers().ToList();
RDFQueryMember lastQueryMbr = evaluableQueryMembers.LastOrDefault();
foreach (var queryMember in evaluableQueryMembers)
{

#region PATTERNGROUPS
Expand Down Expand Up @@ -176,15 +177,17 @@ public override String ToString()
#endregion

#region MODIFIERS
List<RDFModifier> 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

Expand Down
21 changes: 12 additions & 9 deletions RDFSharp/Query/Queries/Describe/RDFDescribeQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RDFQueryMember> evaluableQueryMembers = this.GetEvaluableQueryMembers().ToList();
RDFQueryMember lastQueryMbr = evaluableQueryMembers.LastOrDefault();
foreach (var queryMember in evaluableQueryMembers)
{

#region PATTERNGROUPS
Expand Down Expand Up @@ -164,15 +165,17 @@ public override String ToString()
#endregion

#region MODIFIERS
List<RDFModifier> 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

Expand Down
29 changes: 16 additions & 13 deletions RDFSharp/Query/Queries/Select/RDFSelectQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RDFQueryMember> evaluableQueryMembers = this.GetEvaluableQueryMembers().ToList();
RDFQueryMember lastQueryMbr = evaluableQueryMembers.LastOrDefault();
foreach (var queryMember in evaluableQueryMembers)
{

#region PATTERNGROUPS
Expand Down Expand Up @@ -164,24 +165,26 @@ public override String ToString()
#endregion

#region MODIFIERS
List<RDFModifier> 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

Expand Down

0 comments on commit 5a6f718

Please sign in to comment.