mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
common: inlist code refactoring
introduced INLIST_FOREACH() / INLIST_SAFE_FOREACH() for common implementation
This commit is contained in:
parent
1422c4ca5f
commit
f33b63abad
3 changed files with 20 additions and 21 deletions
|
@ -36,6 +36,11 @@ struct Inlist
|
|||
T* head = nullptr;
|
||||
T* tail = nullptr;
|
||||
|
||||
~Inlist()
|
||||
{
|
||||
free();
|
||||
}
|
||||
|
||||
void free()
|
||||
{
|
||||
while (head) {
|
||||
|
@ -106,6 +111,14 @@ struct Inlist
|
|||
}
|
||||
};
|
||||
|
||||
#define INLIST_FOREACH(inlist, cur) \
|
||||
for (auto cur = inlist.head; cur; cur = cur->next)
|
||||
|
||||
#define INLIST_SAFE_FOREACH(inlist, cur) \
|
||||
auto cur = inlist.head; \
|
||||
auto next = cur ? cur->next : nullptr; \
|
||||
for (; cur; cur = next, next = (cur ? cur->next : nullptr))
|
||||
|
||||
}
|
||||
|
||||
#endif // _TVG_INLIST_H_
|
||||
|
|
|
@ -217,8 +217,6 @@ void LottieBuilder::updateGroup(LottieGroup* parent, LottieObject** child, float
|
|||
contexts.back(new RenderContext(*ctx, propagator, group->mergeable()));
|
||||
|
||||
updateChildren(group, frameNo, contexts);
|
||||
|
||||
contexts.free();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -206,14 +206,11 @@ static LoadModule* _findFromCache(const char* filename)
|
|||
{
|
||||
ScopedLock lock(key);
|
||||
|
||||
auto loader = _activeLoaders.head;
|
||||
|
||||
while (loader) {
|
||||
INLIST_FOREACH(_activeLoaders, loader) {
|
||||
if (loader->pathcache && !strcmp(loader->hashpath, filename)) {
|
||||
++loader->sharing;
|
||||
return loader;
|
||||
}
|
||||
loader = loader->next;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -225,16 +222,13 @@ static LoadModule* _findFromCache(const char* data, uint32_t size, const char* m
|
|||
if (type == FileType::Unknown) return nullptr;
|
||||
|
||||
ScopedLock lock(key);
|
||||
auto loader = _activeLoaders.head;
|
||||
|
||||
auto key = HASH_KEY(data);
|
||||
|
||||
while (loader) {
|
||||
INLIST_FOREACH(_activeLoaders, loader) {
|
||||
if (loader->type == type && loader->hashkey == key) {
|
||||
++loader->sharing;
|
||||
return loader;
|
||||
}
|
||||
loader = loader->next;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -253,15 +247,12 @@ bool LoaderMgr::init()
|
|||
|
||||
bool LoaderMgr::term()
|
||||
{
|
||||
auto loader = _activeLoaders.head;
|
||||
|
||||
//clean up the remained font loaders which is globally used.
|
||||
while (loader && loader->type == FileType::Ttf) {
|
||||
INLIST_SAFE_FOREACH(_activeLoaders, loader) {
|
||||
if (loader->type != FileType::Ttf) break;
|
||||
auto ret = loader->close();
|
||||
auto tmp = loader;
|
||||
loader = loader->next;
|
||||
_activeLoaders.remove(tmp);
|
||||
if (ret) delete(tmp);
|
||||
_activeLoaders.remove(loader);
|
||||
if (ret) delete(loader);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -340,14 +331,11 @@ bool LoaderMgr::retrieve(const char* filename)
|
|||
|
||||
LoadModule* LoaderMgr::loader(const char* key)
|
||||
{
|
||||
auto loader = _activeLoaders.head;
|
||||
|
||||
while (loader) {
|
||||
INLIST_FOREACH(_activeLoaders, loader) {
|
||||
if (loader->pathcache && strstr(loader->hashpath, key)) {
|
||||
++loader->sharing;
|
||||
return loader;
|
||||
}
|
||||
loader = loader->next;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue