From 92bfae03cba66aab930d355cc208c3bc9def8e42 Mon Sep 17 00:00:00 2001 From: "kvisco%ziplink.net" Date: Wed, 6 Sep 2000 07:05:32 +0000 Subject: [PATCH] Not part of regular build, a=leaf. Added the option to destroy objects contained in the list, this feature checks for duplicates in the list before deleting. git-svn-id: svn://10.0.0.236/trunk@78251 18797224-902f-48f8-a5cc-f745e15eee43 --- .../transformiix/source/base/ArrayList.cpp | 34 ++++++++++++++++++- .../transformiix/source/base/ArrayList.h | 9 ++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/mozilla/extensions/transformiix/source/base/ArrayList.cpp b/mozilla/extensions/transformiix/source/base/ArrayList.cpp index ed8ce01bcce..a96be0d1d54 100644 --- a/mozilla/extensions/transformiix/source/base/ArrayList.cpp +++ b/mozilla/extensions/transformiix/source/base/ArrayList.cpp @@ -19,7 +19,7 @@ * Keith Visco, kvisco@ziplink.net * -- original author. * - * $Id: ArrayList.cpp,v 1.1 2000-03-02 09:19:32 kvisco%ziplink.net Exp $ + * $Id: ArrayList.cpp,v 1.2 2000-09-06 07:05:31 kvisco%ziplink.net Exp $ */ #include "ArrayList.h" @@ -116,6 +116,38 @@ void ArrayList::clear() { elementCount = 0; } //-- clear +/** + * Removes all elements from the list + * @param deleteObjects allows specifying whether or not to delete the TxObjects + * that are currently in the list. + *
+ * Note: If object deletion is enabled this method will check for duplicate references + * in the list to prevent possible seg faults and will therefore run slower than an algorithm + * that doesn't check for duplicates. +**/ +void ArrayList::clear(MBool deleteObjects) { + + + if (deleteObjects) { + for (int i = 0; i < elementCount; i++) { + if (elements[i]) { + TxObject* tmp = elements[i]; + elements[i] = 0; + //-- check for duplicates to avoid attempting to free memory that + //-- has already been freed + int idx = i+1; + for ( ; idx < elementCount; idx++) { + if (elements[idx] == tmp) elements[idx] = 0; + } + delete tmp; + } + } + elementCount = 0; + } + else clear(); + +} //-- clear(MBool); + /** * Returns true if the specified TxObject is contained in the list. * @param object the TxObject to search for diff --git a/mozilla/extensions/transformiix/source/base/ArrayList.h b/mozilla/extensions/transformiix/source/base/ArrayList.h index ee140a46516..6a6e15ba45b 100644 --- a/mozilla/extensions/transformiix/source/base/ArrayList.h +++ b/mozilla/extensions/transformiix/source/base/ArrayList.h @@ -19,7 +19,7 @@ * Keith Visco, kvisco@ziplink.net * -- original author. * - * $Id: ArrayList.h,v 1.1 2000-03-02 09:19:38 kvisco%ziplink.net Exp $ + * $Id: ArrayList.h,v 1.2 2000-09-06 07:05:32 kvisco%ziplink.net Exp $ */ /** @@ -76,6 +76,13 @@ public: **/ void clear(); + /** + * Removes all elements from the list + * @param deleteObjects allows specifying whether or not to delete the TxObjects + * that are currently in the list + **/ + void clear(MBool deleteObjects); + /** * Returns true if the specified TxObject is contained in the list. * @param object the TxObject to search for