From c83575f467c2e9bfd52487de5bb0bc637e8cc1ed Mon Sep 17 00:00:00 2001 From: "kvisco%ziplink.net" Date: Wed, 2 Nov 2005 07:34:27 +0000 Subject: [PATCH] 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. --- content/xslt/src/base/txList.cpp | 27 +++++++++++++++++++++++++-- content/xslt/src/base/txList.h | 9 ++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/content/xslt/src/base/txList.cpp b/content/xslt/src/base/txList.cpp index 235d0091a196..4ffa4df6598f 100644 --- a/content/xslt/src/base/txList.cpp +++ b/content/xslt/src/base/txList.cpp @@ -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 Keith Visco - * @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 diff --git a/content/xslt/src/base/txList.h b/content/xslt/src/base/txList.h index ccd197417e78..fd6d18e3e1f6 100644 --- a/content/xslt/src/base/txList.h +++ b/content/xslt/src/base/txList.h @@ -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 **/