From 5e5bb3318e81af2fb1df408a34114dc6e1377ee4 Mon Sep 17 00:00:00 2001 From: Jessica Hamilton Date: Tue, 24 May 2022 16:10:38 +1200 Subject: [PATCH] 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 --- src/kits/support/StringList.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/kits/support/StringList.cpp b/src/kits/support/StringList.cpp index fe6e138ac0..467ac98593 100644 --- a/src/kits/support/StringList.cpp +++ b/src/kits/support/StringList.cpp @@ -296,9 +296,10 @@ BStringList::Join(const char* separator, int32 length) const void BStringList::DoForEach(bool (*func)(const BString& string)) { + bool terminate = false; int32 count = fStrings.CountItems(); - for (int32 i = 0; i < count; i++) - func(StringAt(i)); + for (int32 i = 0; i < count && !terminate; i++) + terminate = func(StringAt(i)); } @@ -306,9 +307,10 @@ void BStringList::DoForEach(bool (*func)(const BString& string, void* arg2), void* arg2) { + bool terminate = false; int32 count = fStrings.CountItems(); - for (int32 i = 0; i < count; i++) - func(StringAt(i), arg2); + for (int32 i = 0; i < count && !terminate; i++) + terminate = func(StringAt(i), arg2); }