Re: [Vala] foreach performance



Sounds like you want a linked list, on those the .remove() is O(1) will not need to iterate over the 
collection.


                Martin


Кутейников Дмитрий wrote:
Hello!
Why there are no operator to remove current object in foreach block?
I have to write

            foreach(Components.Obj obj in m_objects)
            {
                if(obj.item.x == x && obj.item.y == y)
                {
                    Events.disappear(obj);
                    m_objects.remove(obj);  //  :(
                    return obj;
                }

instead of

            foreach(Components.Obj obj in m_objects)
            {
                if(obj.item.x == x && obj.item.y == y)
                {
                    Events.disappear(obj);
                    remove obj;
                    return obj;
                }

/m_objects.remove(obj)/ will start a new search from the beginning of list so it is a great performance hit.


------------------------------------------------------------------------

_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]