Backout 04a196339ca4 (bug 1181443, part 3) so that bug 1182961's patches can be backed out.

--HG--
extra : source : 11f2aec8187f0463c3f89f5e28698a90d1618acd
This commit is contained in:
Nicholas Nethercote 2015-08-06 16:28:13 -07:00
Родитель bfd11788ac
Коммит d606681e8a
2 изменённых файлов: 50 добавлений и 11 удалений

Просмотреть файл

@ -13,17 +13,6 @@
#include "prlock.h"
#include "nsDebug.h"
// These are the codes returned by |EnumReadFunction| and |EnumFunction|, which
// control the behavior of EnumerateRead() and Enumerate(). The PLD/PL_D prefix
// is because they originated in PLDHashTable, but that class no longer uses
// them.
enum PLDHashOperator
{
PL_DHASH_NEXT = 0, // enumerator says continue
PL_DHASH_STOP = 1, // enumerator says stop
PL_DHASH_REMOVE = 2 // enumerator says remove
};
template<class KeyClass, class DataType, class UserDataType>
class nsBaseHashtable; // forward declaration

Просмотреть файл

@ -72,6 +72,16 @@
* @author "Benjamin Smedberg <bsmedberg@covad.net>"
*/
// These are the codes returned by |Enumerator| functions, which control
// EnumerateEntry()'s behavior. The PLD/PL_D prefix is because they originated
// in PLDHashTable, but that class no longer uses them.
enum PLDHashOperator
{
PL_DHASH_NEXT = 0, // enumerator says continue
PL_DHASH_STOP = 1, // enumerator says stop
PL_DHASH_REMOVE = 2 // enumerator says remove
};
template<class EntryType>
class MOZ_NEEDS_NO_VTABLE_TYPE nsTHashtable
{
@ -179,6 +189,46 @@ public:
PL_DHashTableRawRemove(&mTable, aEntry);
}
/**
* client must provide an <code>Enumerator</code> function for
* EnumerateEntries
* @param aEntry the entry being enumerated
* @param userArg passed unchanged from <code>EnumerateEntries</code>
* @return combination of flags
* @link PLDHashOperator::PL_DHASH_NEXT PL_DHASH_NEXT @endlink ,
* @link PLDHashOperator::PL_DHASH_STOP PL_DHASH_STOP @endlink ,
* @link PLDHashOperator::PL_DHASH_REMOVE PL_DHASH_REMOVE @endlink
*/
typedef PLDHashOperator (*Enumerator)(EntryType* aEntry, void* userArg);
/**
* Enumerate all the entries of the function. If any entries are removed via
* a PL_DHASH_REMOVE return value from |aEnumFunc|, the table may be shrunk
* at the end. Use RawRemoveEntry() instead if you wish to remove an entry
* without possibly shrinking the table.
* WARNING: this function is deprecated. Please use Iterator instead.
* @param enumFunc the <code>Enumerator</code> function to call
* @param userArg a pointer to pass to the
* <code>Enumerator</code> function
* @return the number of entries actually enumerated
*/
uint32_t EnumerateEntries(Enumerator aEnumFunc, void* aUserArg)
{
uint32_t n = 0;
for (auto iter = mTable.Iter(); !iter.Done(); iter.Next()) {
auto entry = static_cast<EntryType*>(iter.Get());
PLDHashOperator op = aEnumFunc(entry, aUserArg);
n++;
if (op & PL_DHASH_REMOVE) {
iter.Remove();
}
if (op & PL_DHASH_STOP) {
break;
}
}
return n;
}
// This is an iterator that also allows entry removal. Example usage:
//
// for (auto iter = table.Iter(); !iter.Done(); iter.Next()) {