]> O.S.I.I.S - jp/crow.git/commitdiff
LayoutingQueue as LinkedList<T>, perf improvments not fantastish
authorjpbruyere <jp.bruyere@hotmail.com>
Thu, 4 Feb 2016 21:14:26 +0000 (22:14 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Thu, 4 Feb 2016 21:14:26 +0000 (22:14 +0100)
UnitTest/NUnitCrowWindow.cs
src/GraphicObjects/GraphicObject.cs
src/LayoutingQueue.cs
src/LayoutingQueueItem.cs
src/OpenTKGameWindow.cs

index 1ba9a32e661ccd4c4de1ad98bfc280a9e458be55..999639cd2f1207d32f378689a8f1953acab1d773 100644 (file)
@@ -149,7 +149,7 @@ namespace Crow
                        invGOList = invGOList.Reverse ().ToArray ();
 
                        //Debug.WriteLine ("======= Layouting queue start =======");
-                               while (Interface.LayoutingQueue.Count > 0) {
+                               while (Interface.LayoutingQueue.First != null) {
                                        //                                      Stopwatch lqiProcTime = new Stopwatch ();
                                        //                                      lqiProcTime.Start ();
                                        LayoutingQueueItem lqi = Interface.LayoutingQueue.Dequeue ();
index f6c9c84d0a555b5686f7ebc492b0257648eb7f84..d96bdf297a4c690494a477244b5d9de35eca1a21 100644 (file)
@@ -494,7 +494,7 @@ namespace Crow
                void deleteLQI(int lt){
                        LayoutingQueueItem[] lqis = this.RegisteredLQIs.Where (lq => (lt & (int)lq.LayoutType) > 0).ToArray ();
                        for (int i = 0; i < lqis.Length; i++) {
-                               Interface.LayoutingQueue.Remove (lqis [i]);
+                               Interface.LayoutingQueue.Remove (lqis [i].Node);
                                lqis [i].DeleteLayoutableRef();
                        }
                }
@@ -508,33 +508,37 @@ namespace Crow
                        Debug.WriteLine ("RegisterForLayouting => {1}->{0}", layoutType, this.ToString());
                        #endif
 
-                               deleteLQI (layoutType);
-                               if ((layoutType & (int)LayoutingType.Width) > 0) {
-                                       if (Bounds.Width == 0) //stretch in parent
+                       deleteLQI (layoutType);
+                       if ((layoutType & (int)LayoutingType.Width) > 0) {
+                               if (Bounds.Width == 0) //stretch in parent
                                                Interface.LayoutingQueue.EnqueueAfterParentSizing (LayoutingType.Width, this);
-                                       else if (Bounds.Width < 0) //fit 
+                               else if (Bounds.Width < 0) //fit 
                                                Interface.LayoutingQueue.EnqueueBeforeParentSizing (LayoutingType.Width, this);
-                                       else
-                                               Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Width, this));
+                               else {
+                                       LayoutingQueueItem lqi = new LayoutingQueueItem (LayoutingType.Width, this);
+                                       lqi.Node = Interface.LayoutingQueue.AddFirst (lqi);
                                }
+                       }
 
-                               if ((layoutType & (int)LayoutingType.Height) > 0) {
-                                       if (Bounds.Height == 0) //stretch in parent
+                       if ((layoutType & (int)LayoutingType.Height) > 0) {
+                               if (Bounds.Height == 0) //stretch in parent
                                                Interface.LayoutingQueue.EnqueueAfterParentSizing (LayoutingType.Height, this);
-                                       else if (Bounds.Height < 0) //fit 
+                               else if (Bounds.Height < 0) //fit 
                                                Interface.LayoutingQueue.EnqueueBeforeParentSizing (LayoutingType.Height, this);
-                                       else
-                                               Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Height, this));
+                               else{
+                                       LayoutingQueueItem lqi = new LayoutingQueueItem (LayoutingType.Height, this);
+                                       lqi.Node = Interface.LayoutingQueue.AddFirst (lqi);
                                }
+                       }
 
-                               if ((layoutType & (int)LayoutingType.X) > 0)
+                       if ((layoutType & (int)LayoutingType.X) > 0)
                                        //for x positionning, sizing of parent and this have to be done
                                        Interface.LayoutingQueue.EnqueueAfterThisAndParentSizing (LayoutingType.X, this);
 
-                               if ((layoutType & (int)LayoutingType.Y) > 0)
+                       if ((layoutType & (int)LayoutingType.Y) > 0)
                                        //for x positionning, sizing of parent and this have to be done
                                        Interface.LayoutingQueue.EnqueueAfterThisAndParentSizing (LayoutingType.Y, this);
-                       }
+               }
 
 
                /// <summary> trigger dependant sizing component update </summary>
index 51ec702ebccc5cae88970304152504c0fe12c819..697c59aa6ad873efcd96d1c195b5fb6fe40b2d60 100644 (file)
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Diagnostics;
 
 namespace Crow
 {
-       public class LayoutingQueue : List<LayoutingQueueItem>
+       public class LayoutingQueue : LinkedList<LayoutingQueueItem>
        {
                public LayoutingQueue ()
                {
                }
                public void Enqueue(LayoutingType _lt, ILayoutable _object)
                {
-                       this.Add (new LayoutingQueueItem (_lt, _object));
+                       LayoutingQueueItem lqi = new LayoutingQueueItem (_lt, _object);
+                       lqi.Node = this.AddLast (lqi);
                }
                LayoutingQueueItem searchLqi(ILayoutable go, LayoutingType lt){
                        return go.RegisteredLQIs.Where(lq => lq.LayoutType == lt).LastOrDefault();
@@ -42,9 +44,9 @@ namespace Crow
                        LayoutingQueueItem parentLqi = searchLqi (_object.Parent, _lt);
 
                        if (parentLqi == null)
-                               this.Insert (0, lqi);
+                               lqi.Node = this.AddFirst (lqi);
                        else
-                               this.Insert (this.IndexOf (parentLqi) + 1, lqi);
+                               lqi.Node = this.AddAfter (parentLqi.Node, lqi);
                }
                public void EnqueueBeforeParentSizing (LayoutingType _lt, ILayoutable _object)
                {
@@ -52,9 +54,9 @@ namespace Crow
                        LayoutingQueueItem parentLqi = searchLqi (_object.Parent, _lt);
 
                        if (parentLqi == null)
-                               this.Add (lqi);
+                               lqi.Node = this.AddLast (lqi);
                        else
-                               this.Insert (this.IndexOf (parentLqi), lqi);
+                               lqi.Node = this.AddBefore (parentLqi.Node, lqi);
                }
                public void EnqueueAfterThisAndParentSizing (LayoutingType _lt, ILayoutable _object)
                {
@@ -66,25 +68,38 @@ namespace Crow
 
                        LayoutingQueueItem parentLqi = searchLqi (_object.Parent, sizing);
                        LayoutingQueueItem thisLqi = searchLqi (_object, sizing);
-                       int idx = -1;
 
                        if (parentLqi == null) {
                                if (thisLqi != null)
-                                       idx = this.IndexOf (thisLqi);
+                                       lqi.Node = this.AddAfter (thisLqi.Node, lqi);
+                               else
+                                       lqi.Node = this.AddLast (lqi);
                        } else {
                                if (thisLqi == null)
-                                       idx = this.IndexOf (parentLqi);
-                               else
-                                       idx = Math.Max(this.IndexOf (parentLqi), this.IndexOf (thisLqi));                               
+                                       lqi.Node = this.AddAfter (parentLqi.Node, lqi);
+                               else {
+                                       switch (sizing) {
+                                       case LayoutingType.Width:
+                                               if (_object.Parent.getBounds().Width<0)
+                                                       lqi.Node = this.AddAfter (parentLqi.Node, lqi);
+                                               else
+                                                       lqi.Node = this.AddAfter (thisLqi.Node, lqi);                                                   
+                                               break;
+                                       case LayoutingType.Height:
+                                               if (_object.Parent.getBounds().Height<0)
+                                                       lqi.Node = this.AddAfter (parentLqi.Node, lqi);
+                                               else
+                                                       lqi.Node = this.AddAfter (thisLqi.Node, lqi);                                                   
+                                               break;
+                                       }
+                               }
                        }
-
-                       this.Insert (idx + 1, lqi);                     
                }
                public LayoutingQueueItem Dequeue()
                {
-                       LayoutingQueueItem tmp = this [0];
+                       LayoutingQueueItem tmp = this.First.Value;
                        tmp.DeleteLayoutableRef ();
-                       this.RemoveAt (0);
+                       this.RemoveFirst ();
                        return tmp;
                }
        }
index d1cfaeb95e65a577d64dbde64672d62fa520f1c2..816d1923d6d3bd3208e12631548240b250bef256 100644 (file)
@@ -20,6 +20,7 @@
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 using System;
 using System.Diagnostics;
+using System.Collections.Generic;
 
 namespace Crow
 {
@@ -37,7 +38,7 @@ namespace Crow
 
        public class LayoutingQueueItem
        {
-
+               public LinkedListNode<LayoutingQueueItem> Node;
                public ILayoutable GraphicObject;
                public LayoutingType LayoutType;
 
index 6726a87c14260613b814ac828c9017341919067e..fcd08f95a93f42837f82e79a3266877cf4bb1642 100644 (file)
@@ -261,7 +261,7 @@ namespace Crow
                        #endif
                        //Debug.WriteLine ("======= Layouting queue start =======");
 
-                               while (Interface.LayoutingQueue.Count > 0) {
+                               while (Interface.LayoutingQueue.First != null) {
 //                                     Stopwatch lqiProcTime = new Stopwatch ();
 //                                     lqiProcTime.Start ();
                                        LayoutingQueueItem lqi = Interface.LayoutingQueue.Dequeue ();