]> O.S.I.I.S - jp/crow.git/commitdiff
replace foreach loops with for ones
authorjpbruyere <jp.bruyere@hotmail.com>
Wed, 14 Jun 2017 00:14:48 +0000 (02:14 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Wed, 14 Jun 2017 00:14:48 +0000 (02:14 +0200)
Templates/ToolWindow.template
src/Colors.cs
src/GraphicObjects/GenericStack.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Group.cs
src/Interface.cs

index f021f6ee162de6fa1860adff2173d4694ff542aa..919c0bada2d5f98c49d05cb202ee12042462ef4d 100755 (executable)
@@ -19,6 +19,6 @@
                                <GraphicObject Width="5"/>
                        </HorizontalStack>
 <!--           </Border>-->
-               <Container Name="Content" MinimumSize="50,50" Background="0.5,0.5,0.5,0.5"/>
+               <Container Name="Content" MinimumSize="50,50" />
        </VerticalStack>
 </Border>
index 3f200829a038bae9b04bed9cf5bd60f98f8f82a0..89f5c932fd4011a2f5e4170246de160be54d448c 100644 (file)
@@ -88,10 +88,9 @@ namespace Crow
 
                        if (c.Length == 1)
                        {
-                               foreach (Color cr in ColorDic)
-                               {
-                                       if (string.Equals(cr.Name,s,StringComparison.Ordinal))
-                                               return cr;
+                               for (int i = 0; i < ColorDic.Count; i++) {
+                                       if (string.Equals(ColorDic [i].Name,s,StringComparison.Ordinal))
+                                               return ColorDic [i];
                                }
                        }
                        return new Color(
@@ -1127,12 +1126,10 @@ namespace Crow
                        if (!string.IsNullOrEmpty(Name))
                                return Name;
 
-                       foreach (Color cr in ColorDic)
-                       {
-                               if (cr == this)
-                               {
-                                       Name = cr.Name;
-                                       return cr.Name;
+                       for (int i = 0; i < ColorDic.Count; i++) {
+                               if (ColorDic[i] == this) {
+                                       Name = ColorDic[i].Name;
+                                       return ColorDic[i].Name;
                                }
                        }
 
index cecdaffd5116825561ac2114810960b28fe8042b..a21c903d9123f879073e294c29f7c66c86a8f456 100644 (file)
@@ -97,18 +97,18 @@ namespace Crow
                {
                        int d = 0;
                        if (Orientation == Orientation.Horizontal) {
-                               foreach (GraphicObject c in Children) {
-                                       if (!c.Visible)
+                               for (int i = 0; i < Children.Count; i++) {
+                                       if (!Children[i].Visible)
                                                continue;
-                                       c.Slot.X = d;
-                                       d += c.Slot.Width + Spacing;
+                                       Children[i].Slot.X = d;
+                                       d += Children[i].Slot.Width + Spacing;
                                }
                        } else {
-                               foreach (GraphicObject c in Children) {
-                                       if (!c.Visible)
+                               for (int i = 0; i < Children.Count; i++) {
+                                       if (!Children[i].Visible)
                                                continue;                                       
-                                       c.Slot.Y = d;
-                                       d += c.Slot.Height + Spacing;
+                                       Children[i].Slot.Y = d;
+                                       d += Children[i].Slot.Height + Spacing;
                                }
                        }
                        IsDirty = true;
index 0db8fb54e4ca83d4aa279baba8c6c15c235150f1..46b4c31b81956e903937c34bfc5e1ddf60075f91 100644 (file)
@@ -719,10 +719,10 @@ namespace Crow
                        //set local GraphicObject to root object passed as 1st argument
                        il.Emit (OpCodes.Ldarg_0);
                        il.Emit (OpCodes.Stloc_0);
-
-                       foreach (EventInfo ei in thisType.GetEvents(BindingFlags.Public | BindingFlags.Instance)) {
+                       EventInfo[] eis = thisType.GetEvents(BindingFlags.Public | BindingFlags.Instance);
+                       for (int i = 0; i < eis.Length; i++) {
                                string expression;
-                               if (!getDefaultEvent(ei, styling, out expression))
+                               if (!getDefaultEvent(eis[i], styling, out expression))
                                        continue;
                                //TODO:dynEventHandler could be cached somewhere, maybe a style instanciator class holding the styling delegate and bound to it.
                                foreach (string exp in CompilerServices.splitOnSemiColumnOutsideAccolades(expression)) {
@@ -733,15 +733,15 @@ namespace Crow
                                                //push eventInfo as 1st arg of compile
                                                il.Emit (OpCodes.Ldloc_0);
                                                il.Emit (OpCodes.Call, CompilerServices.miGetType);
-                                               il.Emit (OpCodes.Ldstr, ei.Name);//push event name
+                                               il.Emit (OpCodes.Ldstr, eis[i].Name);//push event name
                                                il.Emit (OpCodes.Call, CompilerServices.miGetEvent);
                                                //push expression as 2nd arg of compile
                                                il.Emit (OpCodes.Ldstr, trimed.Substring (1, trimed.Length - 2));
                                                //push null as 3rd arg, currentNode, not known when instanciing
                                                il.Emit (OpCodes.Ldnull);
                                                il.Emit (OpCodes.Callvirt, CompilerServices.miCompileDynEventHandler);
-                                               il.Emit (OpCodes.Castclass, ei.EventHandlerType);
-                                               il.Emit (OpCodes.Callvirt, ei.AddMethod);
+                                               il.Emit (OpCodes.Castclass, eis[i].EventHandlerType);
+                                               il.Emit (OpCodes.Callvirt, eis[i].AddMethod);
                                        }else
                                                Debug.WriteLine("error in styling, event not handled : " + trimed);
                                }
index 549ca2194d0b959e78245303c0362521e07524a9..ad0d28a0c521d330aedda309a13e0416fa0cd783 100644 (file)
@@ -135,9 +135,10 @@ namespace Crow
                {
                        base.OnDataSourceChanged (this, e);
                        lock (children) {
-                               foreach (GraphicObject g in children)
-                                       if (g.localDataSourceIsNull & g.localLogicalParentIsNull)
-                                               g.OnDataSourceChanged (sender, e);
+                               for (int i = 0; i < children.Count; i++) {
+                                       if (children[i].localDataSourceIsNull & children[i].localLogicalParentIsNull)
+                                               children[i].OnDataSourceChanged (sender, e);
+                               }
                        }
                }
                public override GraphicObject FindByName (string nameToFind)
@@ -146,8 +147,8 @@ namespace Crow
                                return this;
                        GraphicObject tmp = null;
                        lock (children) {
-                               foreach (GraphicObject w in Children) {
-                                       tmp = w.FindByName (nameToFind);
+                               for (int i = 0; i < children.Count; i++) {
+                                       tmp = children[i].FindByName (nameToFind);
                                        if (tmp != null)
                                                break;
                                }
@@ -156,10 +157,10 @@ namespace Crow
                }
                public override bool Contains (GraphicObject goToFind)
                {
-                       foreach (GraphicObject w in Children) {
-                               if (w == goToFind)
+                       for (int i = 0; i < children.Count; i++) {
+                               if (children[i] == goToFind)
                                        return true;
-                               if (w.Contains (goToFind))
+                               if (children[i].Contains (goToFind))
                                        return true;
                        }
                        return false;
@@ -195,19 +196,19 @@ namespace Crow
                        //position smaller objects in group when group size is fit
                        switch (layoutType) {
                        case LayoutingType.Width:
-                               foreach (GraphicObject c in Children){
-                                       if (c.Width.Units == Unit.Percent)
-                                               c.RegisterForLayouting (LayoutingType.Width);
+                               for (int i = 0; i < children.Count; i++) {
+                                       if (children[i].Width.Units == Unit.Percent)
+                                               children[i].RegisterForLayouting (LayoutingType.Width);
                                        else
-                                               c.RegisterForLayouting (LayoutingType.X);
+                                               children[i].RegisterForLayouting (LayoutingType.X);
                                }
                                break;
                        case LayoutingType.Height:
-                               foreach (GraphicObject c in Children) {
-                                       if (c.Height.Units == Unit.Percent)
-                                               c.RegisterForLayouting (LayoutingType.Height);
+                               for (int i = 0; i < children.Count; i++) {
+                                       if (children[i].Height.Units == Unit.Percent)
+                                               children[i].RegisterForLayouting (LayoutingType.Height);
                                        else
-                                               c.RegisterForLayouting (LayoutingType.Y);
+                                               children[i].RegisterForLayouting (LayoutingType.Y);
                                }
                                break;
                        }
@@ -225,8 +226,8 @@ namespace Crow
                        }
 
                        lock (children) {
-                               foreach (GraphicObject g in Children) {
-                                       g.Paint (ref gr);
+                               for (int i = 0; i < children.Count; i++) {
+                                       children[i].Paint (ref gr);
                                }
                        }
                        gr.Restore ();
@@ -247,11 +248,12 @@ namespace Crow
                                        gr.Clip ();
 
                                        lock (Children) {
-                                               foreach (GraphicObject c in Children) {
-                                                       if (!c.Visible)
+                                               for (int i = 0; i < children.Count; i++) {
+                                                       if (!children[i].Visible)
+                                                               continue;
+                                                       if (Clipping.Contains (children[i].Slot + ClientRectangle.Position) == RegionOverlap.Out)
                                                                continue;
-                                                       if (Clipping.intersect (c.Slot + ClientRectangle.Position))
-                                                               c.Paint (ref gr);
+                                                       children[i].Paint (ref gr);
                                                }
                                        }
 
index 8439c31ea64f0caa04ad901ba74bb334f94de447..f451dc563659d5a1093487331d4158170608bc45 100644 (file)
@@ -630,8 +630,8 @@ namespace Crow
                /// <summary>Search a Graphic object in the tree named 'nameToFind'</summary>
                public GraphicObject FindByName (string nameToFind)
                {
-                       foreach (GraphicObject w in GraphicTree) {
-                               GraphicObject r = w.FindByName (nameToFind);
+                       for (int i = 0; i < GraphicTree.Count; i++) {
+                               GraphicObject r = GraphicTree[i].FindByName (nameToFind);
                                if (r != null)
                                        return r;
                        }
@@ -647,8 +647,8 @@ namespace Crow
                                int bmpSize = Math.Abs (stride) * ClientRectangle.Height;
                                bmp = new byte[bmpSize];
 
-                               foreach (GraphicObject g in GraphicTree)
-                                       g.RegisterForLayouting (LayoutingType.All);
+                               for (int i = 0; i < GraphicTree.Count; i++)
+                                       GraphicTree[i].RegisterForLayouting (LayoutingType.All);
 
                                clipping.AddRectangle (clientRectangle);
                        }