From 0bd55cb46a90662e6edd0b4e43a350f5b52f4e60 Mon Sep 17 00:00:00 2001 From: Marco De Salvo Date: Wed, 13 Sep 2023 20:59:16 +0200 Subject: [PATCH] Code optimizations --- .../Query/Mirella/Algebra/RDFPatternGroup.cs | 41 +++++++------------ 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/RDFSharp/Query/Mirella/Algebra/RDFPatternGroup.cs b/RDFSharp/Query/Mirella/Algebra/RDFPatternGroup.cs index 7515a9c3..822f5ffa 100644 --- a/RDFSharp/Query/Mirella/Algebra/RDFPatternGroup.cs +++ b/RDFSharp/Query/Mirella/Algebra/RDFPatternGroup.cs @@ -94,32 +94,20 @@ public RDFPatternGroup AddPattern(RDFPattern pattern) GroupMembers.Add(pattern); //Context - if (pattern.Context is RDFVariable patternContext) - { - if (!Variables.Any(v => v.Equals(patternContext))) - Variables.Add(patternContext); - } + if (pattern.Context is RDFVariable patternContext && !Variables.Any(v => v.Equals(patternContext))) + Variables.Add(patternContext); //Subject - if (pattern.Subject is RDFVariable patternSubject) - { - if (!Variables.Any(v => v.Equals(patternSubject))) - Variables.Add(patternSubject); - } + if (pattern.Subject is RDFVariable patternSubject && !Variables.Any(v => v.Equals(patternSubject))) + Variables.Add(patternSubject); //Predicate - if (pattern.Predicate is RDFVariable patternPredicate) - { - if (!Variables.Any(v => v.Equals(patternPredicate))) - Variables.Add(patternPredicate); - } + if (pattern.Predicate is RDFVariable patternPredicate && !Variables.Any(v => v.Equals(patternPredicate))) + Variables.Add(patternPredicate); //Object - if (pattern.Object is RDFVariable patternObject) - { - if (!Variables.Any(v => v.Equals(patternObject))) - Variables.Add(patternObject); - } + if (pattern.Object is RDFVariable patternObject && !Variables.Any(v => v.Equals(patternObject))) + Variables.Add(patternObject); } return this; } @@ -169,8 +157,10 @@ public RDFPatternGroup AddBind(RDFBind bind) { if (bind != null && !GetBinds().Any(b => b.Equals(bind))) { + #region Guards if (Variables.Any(v => v.Equals(bind.Variable))) throw new RDFQueryException($"Cannot add BIND to pattern group because its variable '{bind.Variable}' already exists at this moment!"); + #endregion GroupMembers.Add(bind); @@ -185,16 +175,13 @@ public RDFPatternGroup AddBind(RDFBind bind) /// public RDFPatternGroup AddFilter(RDFFilter filter) { - if (filter != null) - { - if (!GetFilters().Any(f => f.Equals(filter))) - GroupMembers.Add(filter); - } + if (filter != null && !GetFilters().Any(f => f.Equals(filter))) + GroupMembers.Add(filter); return this; } /// - /// Sets the pattern group to be joined as optional with the previous query member + /// Sets the pattern group to be joined as Optional with the previous query member /// public RDFPatternGroup Optional() { @@ -204,7 +191,7 @@ public RDFPatternGroup Optional() } /// - /// Sets the pattern group to be joined as union with the next query member + /// Sets the pattern group to be joined as Union with the next query member /// public RDFPatternGroup UnionWithNext() {