hrev43519 adds 2 changesets to branch 'master' old head: 7e38e5101fdefa930aa7c18172d95d34e5f8c7a6 new head: f0389daa940ba14fa0828e8d6c1bb3bf8d5dc357 ---------------------------------------------------------------------------- 14fc524: Style and performance fixes. Thanks Ingo and Stephan. f0389da: Fix comment and add a TODO. [ czeidler <haiku@xxxxxxxxxxxxxxxxxx> ] ---------------------------------------------------------------------------- 3 files changed, 45 insertions(+), 27 deletions(-) headers/os/support/StringList.h | 2 +- .../mail_daemon/inbound_protocols/pop3/pop3.cpp | 8 +- src/kits/support/StringList.cpp | 62 ++++++++++------ ############################################################################ Commit: 14fc524be2a3f8eb316576ec58cc8c6b3bbf5e87 URL: http://cgit.haiku-os.org/haiku/commit/?id=14fc524 Author: czeidler <haiku@xxxxxxxxxxxxxxxxxx> Date: Sat Dec 17 01:21:35 2011 UTC Style and performance fixes. Thanks Ingo and Stephan. ---------------------------------------------------------------------------- diff --git a/headers/os/support/StringList.h b/headers/os/support/StringList.h index c067d3c..e58956b 100644 --- a/headers/os/support/StringList.h +++ b/headers/os/support/StringList.h @@ -26,7 +26,7 @@ public: bool Remove(const BString& string, bool ignoreCase = false); - void Remove(const BStringList& list, + bool Remove(const BStringList& list, bool ignoreCase = false); BString Remove(int32 index); bool Remove(int32 index, int32 count); diff --git a/src/kits/support/StringList.cpp b/src/kits/support/StringList.cpp index 4846243..c034047 100644 --- a/src/kits/support/StringList.cpp +++ b/src/kits/support/StringList.cpp @@ -1,15 +1,17 @@ /* - * Copyright 2011, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Copyright 2011, Ingo Weinhold, ingo_weinhold@xxxxxx + * Copyright 2011, Clemens Zeidler <haiku@xxxxxxxxxxxxxxxxxx> + * * Distributed under the terms of the MIT License. */ #include <StringList.h> -#include <TypeConstants.h> #include <algorithm> #include <StringPrivate.h> +#include <TypeConstants.h> static int @@ -127,11 +129,15 @@ BStringList::Remove(const BString& string, bool ignoreCase) } -void +bool BStringList::Remove(const BStringList& list, bool ignoreCase) { - for (int32 i = 0; i < list.CountStrings(); i++) - Remove(list.StringAt(i), ignoreCase); + bool removedAnything = false; + int32 stringCount = list.CountStrings(); + for (int32 i = 0; i < stringCount; i++) + removedAnything |= Remove(list.StringAt(i), ignoreCase); + + return removedAnything; } @@ -346,28 +352,30 @@ ssize_t BStringList::FlattenedSize() const { ssize_t size = 0; - for (int32 i = 0; i < CountStrings(); i++) { - const char* str = StringAt(i).String(); - size += strlen(str) + 1; - } + int32 stringCount = CountStrings(); + for (int32 i = 0; i < stringCount; i++) + size += StringAt(i).Length() + 1; return size; } status_t -BStringList::Flatten(void* buffer, ssize_t size) const +BStringList::Flatten(void* buf, ssize_t size) const { + const char* buffer = (const char*)buf; + if (size < FlattenedSize()) return B_NO_MEMORY; - for (int32 i = 0; i < CountStrings(); i++) { - const char* str = StringAt(i).String(); - ssize_t storeSize = strlen(str) + 1; - memcpy(buffer, str, storeSize); - buffer = (void*)((const char*)buffer + storeSize); + int32 stringCount = CountStrings(); + for (int32 i = 0; i < stringCount; i++) { + BString item = StringAt(i); + ssize_t storeSize = item.Length() + 1; + memcpy((void*)buffer, (const void*)item.String(), storeSize); + buffer += storeSize; } - + return B_OK; } @@ -377,13 +385,21 @@ BStringList::Unflatten(type_code code, const void* buffer, ssize_t size) { if (code != B_STRING_LIST_TYPE) return B_ERROR; - - const char* str = (const char*)buffer; - for (off_t offset = 0; offset < size; offset++) { - if (((int8*)buffer)[offset] == 0) { - Add(str); - str = (const char*)buffer + offset + 1; - } + const char* bufferStart = (const char*)buffer; + + MakeEmpty(); + + off_t offset = 0; + while (offset < size) { + const char* cstring = bufferStart + offset; + size_t restSize = size - offset; + size_t read = strnlen(cstring, restSize); + if (read == restSize) + return B_BAD_VALUE; + + if (!Add(cstring)) + return B_NO_MEMORY; + offset += read + 1; } return B_OK; ############################################################################ Revision: hrev43519 Commit: f0389daa940ba14fa0828e8d6c1bb3bf8d5dc357 URL: http://cgit.haiku-os.org/haiku/commit/?id=f0389da Author: czeidler <haiku@xxxxxxxxxxxxxxxxxx> Date: Sat Dec 17 01:35:22 2011 UTC Fix comment and add a TODO. ---------------------------------------------------------------------------- diff --git a/src/add-ons/mail_daemon/inbound_protocols/pop3/pop3.cpp b/src/add-ons/mail_daemon/inbound_protocols/pop3/pop3.cpp index 91ae3c6..88251a1 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/pop3/pop3.cpp +++ b/src/add-ons/mail_daemon/inbound_protocols/pop3/pop3.cpp @@ -608,10 +608,12 @@ POP3Protocol::CheckForDeletedMessages() Delete(fUniqueIDs.IndexOf(toDelete.StringAt(i))); } - //*(unique_ids) -= to_delete; --- This line causes bad things to - // happen (POP3 client uses the wrong indices to retrieve - // messages). Without it, bad things don't happen. + // Don't remove ids from fUniqueIDs, the indices have to stay the same when + // retrieving new messages. fManifest.Remove(toDelete); + + // TODO: at some point the purged manifest should be written to disk + // otherwise it will grow forever }