lottie/property: code refactoring

introduce the release() method for memory freeing.
This method can be used for any demands.
This commit is contained in:
Hermet Park 2024-03-21 15:05:36 +09:00
parent 727b699223
commit 3cb8c4311d

View file

@ -215,8 +215,14 @@ struct LottieGenericProperty : LottieProperty
T value; T value;
LottieGenericProperty(T v) : value(v) {} LottieGenericProperty(T v) : value(v) {}
LottieGenericProperty() {}
~LottieGenericProperty() ~LottieGenericProperty()
{
release();
}
void release()
{ {
delete(frames); delete(frames);
} }
@ -271,11 +277,17 @@ struct LottiePathSet : LottieProperty
PathSet value; PathSet value;
~LottiePathSet() ~LottiePathSet()
{
release();
}
void release()
{ {
free(value.cmds); free(value.cmds);
free(value.pts); free(value.pts);
if (!frames) return; if (!frames) return;
for (auto p = frames->begin(); p < frames->end(); ++p) { for (auto p = frames->begin(); p < frames->end(); ++p) {
free((*p).value.cmds); free((*p).value.cmds);
free((*p).value.pts); free((*p).value.pts);
@ -461,10 +473,11 @@ struct LottieColorStop : LottieProperty
const_cast<LottieColorStop&>(other).frames = nullptr; const_cast<LottieColorStop&>(other).frames = nullptr;
} else { } else {
value = other.value; value = other.value;
const_cast<LottieColorStop&>(other).value.data = nullptr; const_cast<LottieColorStop&>(other).value = {nullptr, nullptr};
} }
populated = other.populated; populated = other.populated;
count = other.count; count = other.count;
return *this; return *this;
} }
@ -482,6 +495,11 @@ struct LottiePosition : LottieProperty
} }
~LottiePosition() ~LottiePosition()
{
release();
}
void release()
{ {
delete(frames); delete(frames);
} }
@ -616,4 +634,4 @@ using LottieFloat = LottieGenericProperty<float>;
using LottieOpacity = LottieGenericProperty<uint8_t>; using LottieOpacity = LottieGenericProperty<uint8_t>;
using LottieColor = LottieGenericProperty<RGB24>; using LottieColor = LottieGenericProperty<RGB24>;
#endif //_TVG_LOTTIE_PROPERTY_H_ #endif //_TVG_LOTTIE_PROPERTY_H_