BStringList: update DoForEach to abort the iteration early.
* This matches `BList::DoForEach`, and the passed in function was already returning a boolean, but was not used. Change-Id: Ifac94734b6181663726cb7aaa7966c5c0ca59bc8 Reviewed-on: https://review.haiku-os.org/c/haiku/+/5337 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
a0a83410c4
commit
5e5bb3318e
@@ -296,9 +296,10 @@ BStringList::Join(const char* separator, int32 length) const
|
|||||||
void
|
void
|
||||||
BStringList::DoForEach(bool (*func)(const BString& string))
|
BStringList::DoForEach(bool (*func)(const BString& string))
|
||||||
{
|
{
|
||||||
|
bool terminate = false;
|
||||||
int32 count = fStrings.CountItems();
|
int32 count = fStrings.CountItems();
|
||||||
for (int32 i = 0; i < count; i++)
|
for (int32 i = 0; i < count && !terminate; i++)
|
||||||
func(StringAt(i));
|
terminate = func(StringAt(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -306,9 +307,10 @@ void
|
|||||||
BStringList::DoForEach(bool (*func)(const BString& string, void* arg2),
|
BStringList::DoForEach(bool (*func)(const BString& string, void* arg2),
|
||||||
void* arg2)
|
void* arg2)
|
||||||
{
|
{
|
||||||
|
bool terminate = false;
|
||||||
int32 count = fStrings.CountItems();
|
int32 count = fStrings.CountItems();
|
||||||
for (int32 i = 0; i < count; i++)
|
for (int32 i = 0; i < count && !terminate; i++)
|
||||||
func(StringAt(i), arg2);
|
terminate = func(StringAt(i), arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user