From: sub.mohanty@samsung.com Date: Sat, 3 Aug 2019 06:47:11 +0000 (+0900) Subject: optimization/model:refactor LOTData class to optimize memory X-Git-Tag: submit/tizen/20190812.090759^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=13e96f01d2e7d63b457e88870fbc3e0468b147d9;p=platform%2Fcore%2Fuifw%2Flottie-player.git optimization/model:refactor LOTData class to optimize memory As std::string uses short buffer optimization internally and because of structure allignment the size of the LOTData was 32 byte. by handling short buffer optimization ourself now size is reduced from 32byte to 16 byte. Change-Id: Icf7d43fb7f93d3dd9ee568130be7bf250809c98c --- diff --git a/src/lottie/lottiemodel.h b/src/lottie/lottiemodel.h index c8d38bb..87cf59f 100644 --- a/src/lottie/lottiemodel.h +++ b/src/lottie/lottiemodel.h @@ -24,6 +24,7 @@ #include #include #include +#include #include"vpoint.h" #include"vrect.h" #include"vinterpolator.h" @@ -356,7 +357,7 @@ class LOTDataVisitor; class LOTData { public: - enum class Type :short { + enum class Type :unsigned char { Composition = 1, Layer, ShapeGroup, @@ -372,19 +373,52 @@ public: Trim, Repeater }; - explicit LOTData(LOTData::Type type): mType(type){} - inline LOTData::Type type() const {return mType;} - bool isStatic() const{return mStatic;} - void setStatic(bool value) {mStatic = value;} - bool hidden() const {return mHidden;} - void setHidden(bool value) {mHidden = value;} - void setName(const char *str) {mName = str;} - const char* name() const{ return mName.c_str();} + + explicit LOTData(LOTData::Type type):mPtr(nullptr) + { + mData._type = type; + mData._static = true; + mData._shortString = true; + mData._hidden = false; + } + ~LOTData() { if (!shortString() && mPtr) free(mPtr); } + + void setStatic(bool value) { mData._static = value;} + bool isStatic() const {return mData._static;} + bool hidden() const {return mData._hidden;} + void setHidden(bool value) {mData._hidden = value;} + void setType(LOTData::Type type) {mData._type = type;} + LOTData::Type type() const { return mData._type;} + void setName(const char *name) + { + if (name) { + auto len = strlen(name); + if (len < maxShortStringLength) { + setShortString(true); + strncpy ( mData._buffer, name, len+1); + } else { + setShortString(false); + mPtr = strdup(name); + } + + } + } + const char* name() const {return shortString() ? mData._buffer : mPtr;} private: - std::string mName; - bool mStatic{true}; - bool mHidden{false}; - LOTData::Type mType; + static constexpr unsigned char maxShortStringLength = 14; + void setShortString(bool value) {mData._shortString = value;} + bool shortString() const {return mData._shortString;} + struct Data{ + char _buffer[14]; + LOTData::Type _type; + bool _static : 1; + bool _hidden : 1; + bool _shortString : 1; + }; + union { + Data mData; + char *mPtr; + }; }; class LOTGroupData: public LOTData @@ -648,9 +682,9 @@ public: FillRule fillRule() const {return mFillRule;} public: FillRule mFillRule{FillRule::Winding}; /* "r" */ + bool mEnabled{true}; /* "fillEnabled" */ LOTAnimatable mColor; /* "c" */ LOTAnimatable mOpacity{100}; /* "o" */ - bool mEnabled{true}; /* "fillEnabled" */ }; struct LOTDashProperty