[QUESTION] ContainsDirtyContents

Posts   
 
    
mattlant
User
Posts: 16
Joined: 24-Jun-2005
# Posted on: 27-Jun-2005 14:13:17   

In EntityCollectionBase:



        public bool ContainsDirtyContents
        {
            get 
            { 
                bool doesContainDirtyEntities = false;
                for(int i=0;i<List.Count;i++)
                {
                    doesContainDirtyEntities |= ((IEntity)List[i]).Fields.IsDirty;
                }
                return doesContainDirtyEntities; 
            }
        }


But how about this:


        public bool ContainsDirtyContents
        {
            get 
            { 
                for(int i=0;i<List.Count;i++)
                {
                    if(((IEntity)List[i]).Fields.IsDirty) return true;
                }
                return false;; 
            }
        }

Or is there a big performance benifit to ORing over an if? Just imo it would be faster if theres contents changed, which in most of my stuff I would be using this, good chances are there is dirty contents. But that is just me. If this is not the case for most people, well, then I guess it will be ok, not a deal breaker, its still going to be fast anyways. I was just thinking for those cases where there are many entities.

Matt

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 27-Jun-2005 15:01:00   

Good catch!

The current code iterates over the complete collection, and if entity 1 is already dirty, the end result won't change, though the complete collection is processed.

I'll change this in the next build.

Frans Bouma | Lead developer LLBLGen Pro