Switch to BObjectLists where possible
This commit is contained in:
parent
baf09fdd0a
commit
8af0aa7c1d
15
TODO.txt
15
TODO.txt
|
@ -4,14 +4,13 @@ Important Features:
|
|||
|
||||
|
||||
Important improvements:
|
||||
* Stop memory accumulation
|
||||
* A few MB accumulate on every update
|
||||
* ime it's than .1 MB per feed― but if you have several feeds, it can
|
||||
accumulate to a hefty sum after some time. In my case, with ~40 feeds
|
||||
and updates every 30 minutes, it got to about 200MB after a week or
|
||||
so.
|
||||
* _Huge_ problem, but I haven't had luck figuring it out yet…
|
||||
* Move from BLists to BObjectLists where possible
|
||||
* Memory leaks
|
||||
* ~50kb per feed on download (+2MB w 40 feeds)
|
||||
* This leak is in Util.ccp, fetch(). I'm stumped here.
|
||||
* ~20kb per feed on parsing (+1MB w 40 feeds)
|
||||
* Very slight on enqueue
|
||||
* Use path-strings or entry_refs when communicating about feeds inter-threads,
|
||||
and in the queue.
|
||||
* Fix background of Feeds List error status icon (it's black, not transparent)
|
||||
* Make UI friendly to whatever font-size you throw at it
|
||||
* Give a max size to the progress label in FeedsView
|
||||
|
|
|
@ -32,7 +32,7 @@ AtomFeed::AtomFeed(Feed* feed)
|
|||
void
|
||||
AtomFeed::Parse ()
|
||||
{
|
||||
entries = BObjectList<Entry>();
|
||||
entries = BObjectList<Entry>(5, true);
|
||||
tinyxml2::XMLDocument xml;
|
||||
xml.LoadFile(GetCachePath().String());
|
||||
|
||||
|
@ -50,10 +50,7 @@ AtomFeed::Parse ()
|
|||
void
|
||||
AtomFeed::RootParse(tinyxml2::XMLElement* xfeed)
|
||||
{
|
||||
tinyxml2::XMLElement* xauthor = xfeed->FirstChildElement("author");
|
||||
tinyxml2::XMLElement* xentry = xfeed->FirstChildElement("entry");
|
||||
tinyxml2::XMLElement* xlink = xfeed->FirstChildElement("link");
|
||||
tinyxml2::XMLElement* xauthlink = xauthor->FirstChildElement("link");
|
||||
|
||||
bool set = false;
|
||||
|
||||
|
@ -116,7 +113,7 @@ AtomFeed::ParseEntries(tinyxml2::XMLElement* xfeed)
|
|||
xentry = xfeed->FirstChildElement("entry");
|
||||
|
||||
int entryCount = xmlCountSiblings(xentry, "entry");
|
||||
entries = BObjectList<Entry>(entryCount);
|
||||
entries = BObjectList<Entry>(entryCount, true);
|
||||
|
||||
std::cout << "\t-" << entryCount << "-\n";
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ FeedController::FeedController()
|
|||
fMainThread(find_thread(NULL)),
|
||||
fDownloadThread(0),
|
||||
fParseThread(0),
|
||||
fDownloadQueue(new BList()),
|
||||
fDownloadQueue(new BObjectList<Feed>(5, true)),
|
||||
fMessageRunner(new BMessageRunner(be_app, BMessage(kControllerCheck), 50000, -1))
|
||||
|
||||
{
|
||||
|
@ -135,8 +135,9 @@ void
|
|||
FeedController::_ProcessQueueItem()
|
||||
{
|
||||
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));
|
||||
fDownloadQueue->RemoveItemAt(0);
|
||||
|
||||
BMessage downloadInit = BMessage(kDownloadStart);
|
||||
downloadInit.AddString("feed_name", buffer->GetTitle());
|
||||
|
@ -197,6 +198,7 @@ FeedController::_ReceiveStatus()
|
|||
_SendProgress();
|
||||
break;
|
||||
}
|
||||
free(feedBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,11 +208,10 @@ FeedController::_DownloadLoop(void* data)
|
|||
{
|
||||
thread_id main = *((thread_id*)data);
|
||||
thread_id sender;
|
||||
Feed* feedBuffer = (Feed*)malloc(sizeof(Feed));
|
||||
|
||||
|
||||
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 "
|
||||
<< feedBuffer->GetXmlUrl().UrlString() << "…\n";
|
||||
|
@ -221,8 +222,8 @@ FeedController::_DownloadLoop(void* data)
|
|||
else {
|
||||
send_data(main, kDownloadFail, (void*)feedBuffer, sizeof(Feed));
|
||||
}
|
||||
free(feedBuffer);
|
||||
}
|
||||
delete(feedBuffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -232,40 +233,38 @@ FeedController::_ParseLoop(void* data)
|
|||
{
|
||||
thread_id main = *((thread_id*)data);
|
||||
thread_id sender;
|
||||
Feed* feedBuffer = (Feed*)malloc(sizeof(Feed));
|
||||
|
||||
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;
|
||||
int32 entriesCount;
|
||||
int32 entriesCount = 0;
|
||||
BString feedTitle;
|
||||
BUrl feedUrl = feedBuffer->GetXmlUrl();
|
||||
BDirectory outDir = BDirectory(((App*)be_app)->fPreferences->EntryDir());
|
||||
|
||||
if (feedBuffer->IsAtom()) {
|
||||
AtomFeed* feed = (AtomFeed*)malloc(sizeof(AtomFeed));
|
||||
feed = new AtomFeed(feedBuffer);
|
||||
feed->Parse();
|
||||
entries = feed->GetNewEntries();
|
||||
AtomFeed feed(feedBuffer);
|
||||
feed.Parse();
|
||||
entries = feed.GetNewEntries();
|
||||
entriesCount = entries.CountItems();
|
||||
feedTitle = feed->GetTitle();
|
||||
feedTitle = feed.GetTitle();
|
||||
|
||||
for (int i = 0; i < entriesCount; i++)
|
||||
((Entry*)entries.ItemAt(i))->Filetize(outDir);
|
||||
delete feed;
|
||||
entries.ItemAt(i)->Filetize(outDir);
|
||||
entries.MakeEmpty();
|
||||
}
|
||||
else if (feedBuffer->IsRss()) {
|
||||
RssFeed* feed = (RssFeed*)malloc(sizeof(RssFeed));
|
||||
feed = new RssFeed(feedBuffer);
|
||||
feed->Parse();
|
||||
entries = feed->GetNewEntries();
|
||||
RssFeed feed(feedBuffer);
|
||||
feed.Parse();
|
||||
entries = feed.GetNewEntries();
|
||||
entriesCount = entries.CountItems();
|
||||
feedTitle = feed->GetTitle();
|
||||
feedTitle = feed.GetTitle();
|
||||
|
||||
for (int i = 0; i < entriesCount; i++)
|
||||
((Entry*)entries.ItemAt(i))->Filetize(outDir);
|
||||
delete feed;
|
||||
entries.ItemAt(i)->Filetize(outDir);
|
||||
entries.MakeEmpty();
|
||||
}
|
||||
|
||||
|
||||
|
@ -275,9 +274,10 @@ FeedController::_ParseLoop(void* data)
|
|||
else {
|
||||
send_data(main, entriesCount, (void*)feedBuffer, sizeof(Feed));
|
||||
}
|
||||
|
||||
free(feedBuffer);
|
||||
}
|
||||
|
||||
delete (feedBuffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
#define FEEDCONTROLLER_H
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <ObjectList.h>
|
||||
#include <OS.h>
|
||||
|
||||
class BList;
|
||||
class BMessage;
|
||||
class BMessageRunner;
|
||||
class Feed;
|
||||
|
@ -55,7 +55,7 @@ private:
|
|||
thread_id fDownloadThread;
|
||||
thread_id fParseThread;
|
||||
|
||||
BList* fDownloadQueue;
|
||||
BObjectList<Feed>* fDownloadQueue;
|
||||
BMessageRunner* fMessageRunner;
|
||||
};
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ void
|
|||
RssFeed::Parse()
|
||||
{
|
||||
tinyxml2::XMLDocument xml;
|
||||
entries = BObjectList<Entry>();
|
||||
entries = BObjectList<Entry>(5, true);
|
||||
|
||||
Feed::Parse();
|
||||
|
||||
|
@ -83,7 +83,7 @@ RssFeed::ParseEntries(tinyxml2::XMLElement* xchan)
|
|||
xitem = xchan->FirstChildElement("item");
|
||||
|
||||
int entryCount = xmlCountSiblings(xitem, "item");
|
||||
entries = BObjectList<Entry>(entryCount);
|
||||
entries = BObjectList<Entry>(entryCount, true);
|
||||
|
||||
std::cout << "\t-" << entryCount << " entries-\n";
|
||||
|
||||
|
|
|
@ -161,7 +161,10 @@ fetch(BUrl url, BDataIO* reply, BString* hash, int timeout)
|
|||
kill_thread(thread);
|
||||
|
||||
*(hash) = listener.GetHash();
|
||||
return request->Status();
|
||||
int32 status = request->Status();
|
||||
|
||||
delete request;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
|
Ŝarĝante…
Reference in New Issue