Switch to BObjectLists where possible

This commit is contained in:
Jaidyn Ann 2021-03-05 20:35:10 -06:00
parent baf09fdd0a
commit 8af0aa7c1d
6 changed files with 41 additions and 42 deletions

View File

@ -4,14 +4,13 @@ Important Features:
Important improvements: Important improvements:
* Stop memory accumulation * Memory leaks
* A few MB accumulate on every update * ~50kb per feed on download (+2MB w 40 feeds)
* ime it's than .1 MB per feed― but if you have several feeds, it can * This leak is in Util.ccp, fetch(). I'm stumped here.
accumulate to a hefty sum after some time. In my case, with ~40 feeds * ~20kb per feed on parsing (+1MB w 40 feeds)
and updates every 30 minutes, it got to about 200MB after a week or * Very slight on enqueue
so. * Use path-strings or entry_refs when communicating about feeds inter-threads,
* _Huge_ problem, but I haven't had luck figuring it out yet… and in the queue.
* Move from BLists to BObjectLists where possible
* Fix background of Feeds List error status icon (it's black, not transparent) * Fix background of Feeds List error status icon (it's black, not transparent)
* Make UI friendly to whatever font-size you throw at it * Make UI friendly to whatever font-size you throw at it
* Give a max size to the progress label in FeedsView * Give a max size to the progress label in FeedsView

View File

@ -32,7 +32,7 @@ AtomFeed::AtomFeed(Feed* feed)
void void
AtomFeed::Parse () AtomFeed::Parse ()
{ {
entries = BObjectList<Entry>(); entries = BObjectList<Entry>(5, true);
tinyxml2::XMLDocument xml; tinyxml2::XMLDocument xml;
xml.LoadFile(GetCachePath().String()); xml.LoadFile(GetCachePath().String());
@ -50,10 +50,7 @@ AtomFeed::Parse ()
void void
AtomFeed::RootParse(tinyxml2::XMLElement* xfeed) AtomFeed::RootParse(tinyxml2::XMLElement* xfeed)
{ {
tinyxml2::XMLElement* xauthor = xfeed->FirstChildElement("author");
tinyxml2::XMLElement* xentry = xfeed->FirstChildElement("entry"); tinyxml2::XMLElement* xentry = xfeed->FirstChildElement("entry");
tinyxml2::XMLElement* xlink = xfeed->FirstChildElement("link");
tinyxml2::XMLElement* xauthlink = xauthor->FirstChildElement("link");
bool set = false; bool set = false;
@ -116,7 +113,7 @@ AtomFeed::ParseEntries(tinyxml2::XMLElement* xfeed)
xentry = xfeed->FirstChildElement("entry"); xentry = xfeed->FirstChildElement("entry");
int entryCount = xmlCountSiblings(xentry, "entry"); int entryCount = xmlCountSiblings(xentry, "entry");
entries = BObjectList<Entry>(entryCount); entries = BObjectList<Entry>(entryCount, true);
std::cout << "\t-" << entryCount << "-\n"; std::cout << "\t-" << entryCount << "-\n";

View File

@ -24,7 +24,7 @@ FeedController::FeedController()
fMainThread(find_thread(NULL)), fMainThread(find_thread(NULL)),
fDownloadThread(0), fDownloadThread(0),
fParseThread(0), fParseThread(0),
fDownloadQueue(new BList()), fDownloadQueue(new BObjectList<Feed>(5, true)),
fMessageRunner(new BMessageRunner(be_app, BMessage(kControllerCheck), 50000, -1)) fMessageRunner(new BMessageRunner(be_app, BMessage(kControllerCheck), 50000, -1))
{ {
@ -135,8 +135,9 @@ void
FeedController::_ProcessQueueItem() FeedController::_ProcessQueueItem()
{ {
if (has_data(fDownloadThread) && !fDownloadQueue->IsEmpty()) { if (has_data(fDownloadThread) && !fDownloadQueue->IsEmpty()) {
Feed* buffer = (Feed*)(fDownloadQueue->RemoveItem(0)); Feed* buffer = fDownloadQueue->ItemAt(0);
send_data(fDownloadThread, 0, (void*)buffer, sizeof(Feed)); send_data(fDownloadThread, 0, (void*)buffer, sizeof(Feed));
fDownloadQueue->RemoveItemAt(0);
BMessage downloadInit = BMessage(kDownloadStart); BMessage downloadInit = BMessage(kDownloadStart);
downloadInit.AddString("feed_name", buffer->GetTitle()); downloadInit.AddString("feed_name", buffer->GetTitle());
@ -197,6 +198,7 @@ FeedController::_ReceiveStatus()
_SendProgress(); _SendProgress();
break; break;
} }
free(feedBuffer);
} }
} }
@ -206,11 +208,10 @@ FeedController::_DownloadLoop(void* data)
{ {
thread_id main = *((thread_id*)data); thread_id main = *((thread_id*)data);
thread_id sender; thread_id sender;
Feed* feedBuffer = (Feed*)malloc(sizeof(Feed));
while (true) { while (true) {
int32 code = receive_data(&sender, (void*)feedBuffer, sizeof(Feed)); Feed* feedBuffer = (Feed*)malloc(sizeof(Feed));
receive_data(&sender, (void*)feedBuffer, sizeof(Feed));
std::cout << "Downloading feed from " std::cout << "Downloading feed from "
<< feedBuffer->GetXmlUrl().UrlString() << "\n"; << feedBuffer->GetXmlUrl().UrlString() << "\n";
@ -221,8 +222,8 @@ FeedController::_DownloadLoop(void* data)
else { else {
send_data(main, kDownloadFail, (void*)feedBuffer, sizeof(Feed)); send_data(main, kDownloadFail, (void*)feedBuffer, sizeof(Feed));
} }
free(feedBuffer);
} }
delete(feedBuffer);
return 0; return 0;
} }
@ -232,40 +233,38 @@ FeedController::_ParseLoop(void* data)
{ {
thread_id main = *((thread_id*)data); thread_id main = *((thread_id*)data);
thread_id sender; thread_id sender;
Feed* feedBuffer = (Feed*)malloc(sizeof(Feed));
while (true) { while (true) {
int32 code = receive_data(&sender, (void*)feedBuffer, sizeof(Feed)); Feed* feedBuffer = (Feed*)malloc(sizeof(Feed));
receive_data(&sender, (void*)feedBuffer, sizeof(Feed));
BObjectList<Entry> entries; BObjectList<Entry> entries;
int32 entriesCount; int32 entriesCount = 0;
BString feedTitle; BString feedTitle;
BUrl feedUrl = feedBuffer->GetXmlUrl(); BUrl feedUrl = feedBuffer->GetXmlUrl();
BDirectory outDir = BDirectory(((App*)be_app)->fPreferences->EntryDir()); BDirectory outDir = BDirectory(((App*)be_app)->fPreferences->EntryDir());
if (feedBuffer->IsAtom()) { if (feedBuffer->IsAtom()) {
AtomFeed* feed = (AtomFeed*)malloc(sizeof(AtomFeed)); AtomFeed feed(feedBuffer);
feed = new AtomFeed(feedBuffer); feed.Parse();
feed->Parse(); entries = feed.GetNewEntries();
entries = feed->GetNewEntries();
entriesCount = entries.CountItems(); entriesCount = entries.CountItems();
feedTitle = feed->GetTitle(); feedTitle = feed.GetTitle();
for (int i = 0; i < entriesCount; i++) for (int i = 0; i < entriesCount; i++)
((Entry*)entries.ItemAt(i))->Filetize(outDir); entries.ItemAt(i)->Filetize(outDir);
delete feed; entries.MakeEmpty();
} }
else if (feedBuffer->IsRss()) { else if (feedBuffer->IsRss()) {
RssFeed* feed = (RssFeed*)malloc(sizeof(RssFeed)); RssFeed feed(feedBuffer);
feed = new RssFeed(feedBuffer); feed.Parse();
feed->Parse(); entries = feed.GetNewEntries();
entries = feed->GetNewEntries();
entriesCount = entries.CountItems(); entriesCount = entries.CountItems();
feedTitle = feed->GetTitle(); feedTitle = feed.GetTitle();
for (int i = 0; i < entriesCount; i++) for (int i = 0; i < entriesCount; i++)
((Entry*)entries.ItemAt(i))->Filetize(outDir); entries.ItemAt(i)->Filetize(outDir);
delete feed; entries.MakeEmpty();
} }
@ -275,9 +274,10 @@ FeedController::_ParseLoop(void* data)
else { else {
send_data(main, entriesCount, (void*)feedBuffer, sizeof(Feed)); send_data(main, entriesCount, (void*)feedBuffer, sizeof(Feed));
} }
free(feedBuffer);
} }
delete (feedBuffer);
return 0; return 0;
} }

View File

@ -6,9 +6,9 @@
#define FEEDCONTROLLER_H #define FEEDCONTROLLER_H
#include <SupportDefs.h> #include <SupportDefs.h>
#include <ObjectList.h>
#include <OS.h> #include <OS.h>
class BList;
class BMessage; class BMessage;
class BMessageRunner; class BMessageRunner;
class Feed; class Feed;
@ -55,7 +55,7 @@ private:
thread_id fDownloadThread; thread_id fDownloadThread;
thread_id fParseThread; thread_id fParseThread;
BList* fDownloadQueue; BObjectList<Feed>* fDownloadQueue;
BMessageRunner* fMessageRunner; BMessageRunner* fMessageRunner;
}; };

View File

@ -31,7 +31,7 @@ void
RssFeed::Parse() RssFeed::Parse()
{ {
tinyxml2::XMLDocument xml; tinyxml2::XMLDocument xml;
entries = BObjectList<Entry>(); entries = BObjectList<Entry>(5, true);
Feed::Parse(); Feed::Parse();
@ -83,7 +83,7 @@ RssFeed::ParseEntries(tinyxml2::XMLElement* xchan)
xitem = xchan->FirstChildElement("item"); xitem = xchan->FirstChildElement("item");
int entryCount = xmlCountSiblings(xitem, "item"); int entryCount = xmlCountSiblings(xitem, "item");
entries = BObjectList<Entry>(entryCount); entries = BObjectList<Entry>(entryCount, true);
std::cout << "\t-" << entryCount << " entries-\n"; std::cout << "\t-" << entryCount << " entries-\n";

View File

@ -161,7 +161,10 @@ fetch(BUrl url, BDataIO* reply, BString* hash, int timeout)
kill_thread(thread); kill_thread(thread);
*(hash) = listener.GetHash(); *(hash) = listener.GetHash();
return request->Status(); int32 status = request->Status();
delete request;
return status;
} }