mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-05 08:35:26 +00:00
Not part of build, a=leaf
Added the get(int) method, for accessing via index. It's not recommended using this method unless on very small lists. This will help save on overhead so we don't have to create an iterator on lists with only a couple elements.
This commit is contained in:
parent
5a40d6128b
commit
c83575f467
@ -23,7 +23,7 @@
|
||||
* Bob Miller, kbob@oblix.com
|
||||
* -- plugged core leak.
|
||||
*
|
||||
* $Id: txList.cpp,v 1.3 1999/11/25 03:03:02 kvisco%ziplink.net Exp $
|
||||
* $Id: txList.cpp,v 1.4 2005/11/02 07:33:45 kvisco%ziplink.net Exp $
|
||||
*/
|
||||
|
||||
#include "List.h"
|
||||
@ -36,7 +36,7 @@
|
||||
/**
|
||||
* Default constructor for a List;
|
||||
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
|
||||
* @version $Revision: 1.3 $ $Date: 1999/11/25 03:03:02 $
|
||||
* @version $Revision: 1.4 $ $Date: 2005/11/02 07:33:45 $
|
||||
**/
|
||||
|
||||
List::List() {
|
||||
@ -75,6 +75,29 @@ void List::add(void* objPtr) {
|
||||
insert(itemCount, objPtr);
|
||||
} //-- add
|
||||
|
||||
/**
|
||||
* Returns the object located at the given index. This may
|
||||
* be slow or fast depending on the implementation.
|
||||
* Note:
|
||||
* Currently this list is implemented via a linked list, so
|
||||
* this method will be slow (unless the list only has a couple
|
||||
* members) as it will need traverse the links each time
|
||||
* @return the object located at the given index
|
||||
**/
|
||||
void* List::get(int index) {
|
||||
|
||||
if ((index < 0) || (index >= itemCount)) return 0;
|
||||
|
||||
int c = 0;
|
||||
ListItem* item = firstItem;
|
||||
while (c != index) {
|
||||
item = item->nextItem;
|
||||
++c;
|
||||
}
|
||||
|
||||
return item->objPtr;
|
||||
} //-- get(int)
|
||||
|
||||
List::ListItem* List::getFirstItem() {
|
||||
return firstItem;
|
||||
} //-- getFirstItem
|
||||
|
@ -21,7 +21,7 @@
|
||||
* Keith Visco, kvisco@ziplink.net
|
||||
* -- original author.
|
||||
*
|
||||
* $Id: txList.h,v 1.5 2005/11/02 07:33:46 kvisco%ziplink.net Exp $
|
||||
* $Id: txList.h,v 1.6 2005/11/02 07:33:47 kvisco%ziplink.net Exp $
|
||||
*/
|
||||
|
||||
#include "baseutils.h"
|
||||
@ -48,6 +48,13 @@ public:
|
||||
**/
|
||||
virtual ~List();
|
||||
|
||||
/**
|
||||
* Returns the object located at the given index. This may
|
||||
* be slow or fast depending on the implementation.
|
||||
* @return the object located at the given index
|
||||
**/
|
||||
void* get(int index);
|
||||
|
||||
/**
|
||||
* Returns the number of items in this List
|
||||
**/
|
||||
|
Loading…
Reference in New Issue
Block a user