From fa504a86032a71a3eb564addd2c5ca1ae8b05e96 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Tue, 25 Feb 2003 12:42:28 +0000 Subject: [PATCH] Use a while loop instead of a for loop. Makes it easier to erase an element. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6243 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/support/ChangeLog | 6 +++++- src/support/forkedcontr.C | 15 +++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/support/ChangeLog b/src/support/ChangeLog index cbedf2c0d4..fa3ffcaeb7 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,8 @@ +2003-02-25 Angus Leeming + + * forkedcontr.C (timer): Use a while loop rather than for; makes it + easier to erase an element. + 2003-02-25 Alfredo Braunstein * forkedcontr.C (timer): don't start a running timer. @@ -6,7 +11,6 @@ * filetools.C (PutEnv): removed (unused) - 2003-02-17 John Levon * forkedcall.h: diff --git a/src/support/forkedcontr.C b/src/support/forkedcontr.C index f34fc3b75f..1a2efbcf18 100644 --- a/src/support/forkedcontr.C +++ b/src/support/forkedcontr.C @@ -83,8 +83,9 @@ void ForkedcallsController::timer() { ListType::size_type start_size = forkedCalls.size(); - for (ListType::iterator it = forkedCalls.begin(); - it != forkedCalls.end(); ++it) { + ListType::iterator it = forkedCalls.begin(); + ListType::iterator end = forkedCalls.end(); + while (it != end) { ForkedProcess * actCall = *it; pid_t pid = actCall->pid(); @@ -133,12 +134,10 @@ void ForkedcallsController::timer() // Emit signal and remove the item from the list actCall->emitSignal(); delete actCall; - // erase returns the next iterator, so decrement it - // to continue the loop. - ListType::iterator prev = it; - --prev; - forkedCalls.erase(it); - it = prev; + // erase returns the next element in the list + it = forkedCalls.erase(it); + } else { + ++it; } }