Fixed various incorrect uses of the erase() method of several STL containers I introduced before. Thanks to Stefano for the hint!

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21332 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2007-06-05 17:45:02 +00:00
parent 2f03d0e0ed
commit 618b37dc46
4 changed files with 24 additions and 22 deletions
+10 -10
View File
@@ -690,7 +690,7 @@ ObserverList::_ValidateHandlers(uint32 what)
} }
Add(target, what); Add(target, what);
handlers.erase(iterator); iterator = handlers.erase(iterator);
} }
} }
@@ -707,7 +707,7 @@ ObserverList::_SendNotices(uint32 what, BMessage* message)
while (iterator != messengers.end()) { while (iterator != messengers.end()) {
if (!(*iterator).IsValid()) { if (!(*iterator).IsValid()) {
messengers.erase(iterator); iterator = messengers.erase(iterator);
continue; continue;
} }
@@ -793,10 +793,10 @@ ObserverList::Remove(const BHandler *handler, uint32 what)
vector<const BHandler*> &handlers = fHandlerMap[what]; vector<const BHandler*> &handlers = fHandlerMap[what];
vector<const BHandler*>::iterator iter; vector<const BHandler*>::iterator iterator = find(handlers.begin(),
iter = find(handlers.begin(), handlers.end(), handler); handlers.end(), handler);
if (iter != handlers.end()) { if (iterator != handlers.end()) {
handlers.erase(iter); handlers.erase(iterator);
if (handlers.empty()) if (handlers.empty())
fHandlerMap.erase(what); fHandlerMap.erase(what);
@@ -812,10 +812,10 @@ ObserverList::Remove(const BMessenger &messenger, uint32 what)
{ {
vector<BMessenger> &messengers = fMessengerMap[what]; vector<BMessenger> &messengers = fMessengerMap[what];
vector<BMessenger>::iterator iter; vector<BMessenger>::iterator iterator = find(messengers.begin(),
iter = find(messengers.begin(), messengers.end(), messenger); messengers.end(), messenger);
if (iter != messengers.end()) { if (iterator != messengers.end()) {
messengers.erase(iter); messengers.erase(iterator);
if (messengers.empty()) if (messengers.empty())
fMessengerMap.erase(what); fMessengerMap.erase(what);
+3 -3
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2005, Haiku. * Copyright 2001-2007, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -132,7 +132,7 @@ RegistrarThreadManager::CleanupThreads()
} else { } else {
OUT("WARNING: RegistrarThreadManager::CleanupThreads(): NULL mime_update_thread_shared_data " OUT("WARNING: RegistrarThreadManager::CleanupThreads(): NULL mime_update_thread_shared_data "
"pointer found in and removed from RegistrarThreadManager::fThreads list\n"); "pointer found in and removed from RegistrarThreadManager::fThreads list\n");
i = fThreads.erase(i); fThreads.erase(i);
} }
i = next; i = next;
@@ -168,7 +168,7 @@ RegistrarThreadManager::ShutdownThreads()
} else { } else {
OUT("WARNING: RegistrarThreadManager::ShutdownThreads(): NULL mime_update_thread_shared_data " OUT("WARNING: RegistrarThreadManager::ShutdownThreads(): NULL mime_update_thread_shared_data "
"pointer found in and removed from RegistrarThreadManager::fThreads list\n"); "pointer found in and removed from RegistrarThreadManager::fThreads list\n");
i = fThreads.erase(i); fThreads.erase(i);
} }
i = next; i = next;
+3 -3
View File
@@ -813,11 +813,11 @@ BPathMonitor::StopWatching(BMessenger target)
return B_BAD_VALUE; return B_BAD_VALUE;
struct watcher* watcher = iterator->second; struct watcher* watcher = iterator->second;
HandlerMap::iterator i = watcher->handlers.begin(); while (!watcher->handlers.empty()) {
for (; i != watcher->handlers.end(); i++) { HandlerMap::iterator i = watcher->handlers.begin();
PathHandler* handler = i->second; PathHandler* handler = i->second;
watcher->handlers.erase(i); watcher->handlers.erase(i);
if (handler->LockLooper()) if (handler->LockLooper())
handler->Quit(); handler->Quit();
} }
+8 -6
View File
@@ -838,14 +838,12 @@ BTranslatorRoster::Private::_CompareSupport(const void* _a, const void* _b)
void void
BTranslatorRoster::Private::_RescanChanged() BTranslatorRoster::Private::_RescanChanged()
{ {
EntryRefSet::iterator iterator = fRescanEntries.begin(); while (!fRescanEntries.empty()) {
EntryRefSet::iterator iterator = fRescanEntries.begin();
while (iterator != fRescanEntries.end()) {
int32 count; int32 count;
CreateTranslators(*iterator, count); CreateTranslators(*iterator, count);
fRescanEntries.erase(iterator); fRescanEntries.erase(iterator);
iterator++;
} }
} }
@@ -1002,7 +1000,8 @@ BTranslatorRoster::Private::_IsKnownDirectory(const node_ref& nodeRef) const
void void
BTranslatorRoster::Private::_RemoveTranslators(const node_ref* nodeRef, const entry_ref* ref) BTranslatorRoster::Private::_RemoveTranslators(const node_ref* nodeRef,
const entry_ref* ref)
{ {
if (ref == NULL && nodeRef == NULL) if (ref == NULL && nodeRef == NULL)
return; return;
@@ -1012,6 +1011,9 @@ BTranslatorRoster::Private::_RemoveTranslators(const node_ref* nodeRef, const en
image_id image = -1; image_id image = -1;
while (iterator != fTranslators.end()) { while (iterator != fTranslators.end()) {
TranslatorMap::iterator next = iterator;
next++;
const translator_item& item = iterator->second; const translator_item& item = iterator->second;
if ((ref != NULL && item.ref == *ref) if ((ref != NULL && item.ref == *ref)
|| (nodeRef != NULL && item.ref.device == nodeRef->device || (nodeRef != NULL && item.ref.device == nodeRef->device
@@ -1026,7 +1028,7 @@ BTranslatorRoster::Private::_RemoveTranslators(const node_ref* nodeRef, const en
fTranslators.erase(iterator); fTranslators.erase(iterator);
} }
iterator++; iterator = next;
} }
// Unload image from the removed translator // Unload image from the removed translator