mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-09 06:04:03 +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* head = nullptr;
|
||||||
T* tail = nullptr;
|
T* tail = nullptr;
|
||||||
|
|
||||||
|
~Inlist()
|
||||||
|
{
|
||||||
|
free();
|
||||||
|
}
|
||||||
|
|
||||||
void free()
|
void free()
|
||||||
{
|
{
|
||||||
while (head) {
|
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_
|
#endif // _TVG_INLIST_H_
|
||||||
|
|
|
@ -217,8 +217,6 @@ void LottieBuilder::updateGroup(LottieGroup* parent, LottieObject** child, float
|
||||||
contexts.back(new RenderContext(*ctx, propagator, group->mergeable()));
|
contexts.back(new RenderContext(*ctx, propagator, group->mergeable()));
|
||||||
|
|
||||||
updateChildren(group, frameNo, contexts);
|
updateChildren(group, frameNo, contexts);
|
||||||
|
|
||||||
contexts.free();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -206,14 +206,11 @@ static LoadModule* _findFromCache(const char* filename)
|
||||||
{
|
{
|
||||||
ScopedLock lock(key);
|
ScopedLock lock(key);
|
||||||
|
|
||||||
auto loader = _activeLoaders.head;
|
INLIST_FOREACH(_activeLoaders, loader) {
|
||||||
|
|
||||||
while (loader) {
|
|
||||||
if (loader->pathcache && !strcmp(loader->hashpath, filename)) {
|
if (loader->pathcache && !strcmp(loader->hashpath, filename)) {
|
||||||
++loader->sharing;
|
++loader->sharing;
|
||||||
return loader;
|
return loader;
|
||||||
}
|
}
|
||||||
loader = loader->next;
|
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -225,16 +222,13 @@ static LoadModule* _findFromCache(const char* data, uint32_t size, const char* m
|
||||||
if (type == FileType::Unknown) return nullptr;
|
if (type == FileType::Unknown) return nullptr;
|
||||||
|
|
||||||
ScopedLock lock(key);
|
ScopedLock lock(key);
|
||||||
auto loader = _activeLoaders.head;
|
|
||||||
|
|
||||||
auto key = HASH_KEY(data);
|
auto key = HASH_KEY(data);
|
||||||
|
|
||||||
while (loader) {
|
INLIST_FOREACH(_activeLoaders, loader) {
|
||||||
if (loader->type == type && loader->hashkey == key) {
|
if (loader->type == type && loader->hashkey == key) {
|
||||||
++loader->sharing;
|
++loader->sharing;
|
||||||
return loader;
|
return loader;
|
||||||
}
|
}
|
||||||
loader = loader->next;
|
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -253,15 +247,12 @@ bool LoaderMgr::init()
|
||||||
|
|
||||||
bool LoaderMgr::term()
|
bool LoaderMgr::term()
|
||||||
{
|
{
|
||||||
auto loader = _activeLoaders.head;
|
|
||||||
|
|
||||||
//clean up the remained font loaders which is globally used.
|
//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 ret = loader->close();
|
||||||
auto tmp = loader;
|
_activeLoaders.remove(loader);
|
||||||
loader = loader->next;
|
if (ret) delete(loader);
|
||||||
_activeLoaders.remove(tmp);
|
|
||||||
if (ret) delete(tmp);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -340,14 +331,11 @@ bool LoaderMgr::retrieve(const char* filename)
|
||||||
|
|
||||||
LoadModule* LoaderMgr::loader(const char* key)
|
LoadModule* LoaderMgr::loader(const char* key)
|
||||||
{
|
{
|
||||||
auto loader = _activeLoaders.head;
|
INLIST_FOREACH(_activeLoaders, loader) {
|
||||||
|
|
||||||
while (loader) {
|
|
||||||
if (loader->pathcache && strstr(loader->hashpath, key)) {
|
if (loader->pathcache && strstr(loader->hashpath, key)) {
|
||||||
++loader->sharing;
|
++loader->sharing;
|
||||||
return loader;
|
return loader;
|
||||||
}
|
}
|
||||||
loader = loader->next;
|
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue