Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Development

Development::Development Forum for development topics and for those interested in EQEMu development. (Not a support forum)

Reply
 
Thread Tools Display Modes
  #1  
Old 10-11-2012, 11:11 PM
Uleat's Avatar
Uleat
Developer
 
Join Date: Apr 2012
Location: North Carolina
Posts: 2,815
Default list.IsEmpty() vs. list.Count()==0

I'm all for not fixing something that isn't broke, so this is more of a muse than anything...


Would there be any realized benefits in converting 'empty list' checks to the 'list.isempty()' method?

There are a few in the code already, but there are a lot of 'list.count()==0' types in there as well.


It probably wouldn't do anything for small population servers, but it might save some cycles on heavy-use ones.
__________________
Uleat of Bertoxxulous

Compilin' Dirty
Reply With Quote
  #2  
Old 10-12-2012, 07:34 AM
lerxst2112
Demi-God
 
Join Date: Aug 2010
Posts: 1,742
Default

It depends on the implementation of list. list::empty() is guaranteed to be a constant time check, where list::size() can be linear time. In practice most implementations of list are such that both are constant time operations since the size is cached.

The reason an implementation might choose to have list::size() be a linear time operation would be so list::splice() is a constant time operation rather than having to count how many nodes were spliced to update the count. The only implementations I know of that did it that way for that specific reason are the sgi / STLPort variations which we don't use.

For all standard library containers it is considered more correct to check for empty() rather than size() == 0, but I probably wouldn't refactor working code to change just that unless it was to fix an actual performance problem versus a theoretical one.
Reply With Quote
  #3  
Old 10-12-2012, 07:08 PM
Uleat's Avatar
Uleat
Developer
 
Join Date: Apr 2012
Location: North Carolina
Posts: 2,815
Default

Understood! Thanks lerxst!
__________________
Uleat of Bertoxxulous

Compilin' Dirty
Reply With Quote
  #4  
Old 10-17-2012, 12:32 PM
KLS
Administrator
 
Join Date: Sep 2006
Posts: 1,348
Default

He's probably referring to the fact that we use two different kinds of linked list classes in the code, STL and a linked list that we used pre-STL (because passable template support in MSVC is something that only came in 2003). In our homemade version LinkedList::Count is constant time because we cache the size and have no empty function.

Also interesting to know: while currently list::size can be in constant or linear time C++11 dictates that it is to be only in constant time.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 04:07 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3