binary size optimization.
authorHermet Park <chuneon.park@samsung.com>
Thu, 4 Nov 2021 09:53:53 +0000 (18:53 +0900)
committerJunsuChoi <jsuya.choi@samsung.com>
Fri, 5 Nov 2021 01:58:14 +0000 (10:58 +0900)
replaced new/delete with malloc/free

saved 936 bytes

src/lib/gl_engine/tvgGlProgram.cpp
src/lib/gl_engine/tvgGlShader.cpp
src/lib/sw_engine/tvgSwCommon.h
src/lib/sw_engine/tvgSwMemPool.cpp
src/lib/tvgFill.cpp
src/lib/tvgFill.h
src/lib/tvgShapeImpl.h

index e7a71b5..a8e7485 100644 (file)
@@ -163,10 +163,10 @@ void GlProgram::linkProgram(std::shared_ptr<GlShader> shader)
         glGetProgramiv(progObj, GL_INFO_LOG_LENGTH, &infoLen);
         if (infoLen > 0)
         {
-            char* infoLog = new char[infoLen];
+            auto infoLog = static_cast<char*>(malloc(sizeof(char) * infoLen));
             glGetProgramInfoLog(progObj, infoLen, NULL, infoLog);
             TVGERR("GL_ENGINE", "Error linking shader: %s", infoLog);
-            delete[] infoLog;
+            free(infoLog);
 
         }
         glDeleteProgram(progObj);
index 89c635f..1c3a2c6 100644 (file)
@@ -84,7 +84,7 @@ uint32_t GlShader::complileShader(uint32_t type, char* shaderSrc)
 
         if (infoLen > 0)
         {
-            char* infoLog = new char[infoLen];
+            auto infoLog = static_cast<char*>(malloc(sizeof(char)*infoLen));
             glGetShaderInfoLog(shader, infoLen, NULL, infoLog);
             TVGERR("GL_ENGINE", "Error compiling shader: %s", infoLog);
             delete[] infoLog;
index 61c6a68..a5272c5 100644 (file)
@@ -251,9 +251,9 @@ struct SwCompositor : Compositor
 
 struct SwMpool
 {
-    SwOutline* outline = nullptr;
-    SwOutline* strokeOutline = nullptr;
-    unsigned allocSize = 0;
+    SwOutline* outline;
+    SwOutline* strokeOutline;
+    unsigned allocSize;
 };
 
 static inline SwCoord TO_SWCOORD(float val)
index 5bf15d7..a44be85 100644 (file)
@@ -61,7 +61,7 @@ SwMpool* mpoolInit(unsigned threads)
 {
     if (threads == 0) threads = 1;
 
-    auto mpool = new SwMpool;
+    auto mpool = static_cast<SwMpool*>(calloc(sizeof(SwMpool), 1));
     mpool->outline = static_cast<SwOutline*>(calloc(1, sizeof(SwOutline) * threads));
     if (!mpool->outline) goto err;
 
@@ -82,7 +82,7 @@ err:
         free(mpool->strokeOutline);
         mpool->strokeOutline = nullptr;
     }
-    delete(mpool);
+    free(mpool);
     return nullptr;
 }
 
@@ -150,7 +150,7 @@ bool mpoolTerm(SwMpool* mpool)
         mpool->strokeOutline = nullptr;
     }
 
-    delete(mpool);
+    free(mpool);
 
     return true;
 }
\ No newline at end of file
index ab059c7..f26168a 100644 (file)
@@ -89,7 +89,9 @@ FillSpread Fill::spread() const noexcept
 
 Result Fill::transform(const Matrix& m) noexcept
 {
-    if (!pImpl->transform) pImpl->transform = new Matrix();
+    if (!pImpl->transform) {
+        pImpl->transform = static_cast<Matrix*>(malloc(sizeof(Matrix)));
+    }
     *pImpl->transform = m;
     return Result::Success;
 }
index af33c06..4251849 100644 (file)
@@ -58,8 +58,8 @@ struct Fill::Impl
     ~Impl()
     {
         if (dup) delete(dup);
-        if (colorStops) free(colorStops);
-        if (transform) delete(transform);
+        free(colorStops);
+        free(transform);
     }
 
     void method(DuplicateMethod<Fill>* dup)
@@ -77,7 +77,7 @@ struct Fill::Impl
         ret->pImpl->colorStops = static_cast<ColorStop*>(malloc(sizeof(ColorStop) * cnt));
         memcpy(ret->pImpl->colorStops, colorStops, sizeof(ColorStop) * cnt);
         if (transform) {
-            ret->pImpl->transform = new Matrix;
+            ret->pImpl->transform = static_cast<Matrix*>(malloc(sizeof(Matrix)));
             *ret->pImpl->transform = *transform;
         }
         return ret;
index 84af1e6..c887f04 100644 (file)
 
 struct ShapeStroke
 {
-    float width = 0;
-    uint8_t color[4] = {0, 0, 0, 0};
-    Fill *fill = nullptr;
-    float* dashPattern = nullptr;
-    uint32_t dashCnt = 0;
-    StrokeCap cap = StrokeCap::Square;
-    StrokeJoin join = StrokeJoin::Bevel;
-
-    ShapeStroke() {}
-
-    ShapeStroke(const ShapeStroke* src)
-     : width(src->width),
-       dashCnt(src->dashCnt),
-       cap(src->cap),
-       join(src->join)
+    float width;
+    uint8_t color[4];
+    Fill *fill;
+    float* dashPattern;
+    uint32_t dashCnt;
+    StrokeCap cap;
+    StrokeJoin join;
+
+    void copy(const ShapeStroke* src)
     {
+       width = src->width;
+       dashCnt = src->dashCnt;
+       cap = src->cap;
+       join = src->join;
+
         memcpy(color, src->color, sizeof(color));
         if (dashCnt > 0) {
             dashPattern = static_cast<float*>(malloc(sizeof(float) * dashCnt));
@@ -55,7 +54,7 @@ struct ShapeStroke
         if (src->fill) fill = src->fill->duplicate();
     }
 
-    ~ShapeStroke()
+    void clear()
     {
         if (dashPattern) free(dashPattern);
         if (fill) delete(fill);
@@ -215,7 +214,10 @@ struct Shape::Impl
     ~Impl()
     {
         if (fill) delete(fill);
-        if (stroke) delete(stroke);
+        if (stroke) {
+            stroke->clear();
+            free (stroke);
+        }
     }
 
     bool dispose(RenderMethod& renderer)
@@ -260,7 +262,7 @@ struct Shape::Impl
     {
         //TODO: Size Exception?
 
-        if (!stroke) stroke = new ShapeStroke();
+        if (!stroke) stroke = static_cast<ShapeStroke*>(calloc(sizeof(ShapeStroke), 1));
         stroke->width = width;
         flag |= RenderUpdateFlag::Stroke;
 
@@ -269,7 +271,7 @@ struct Shape::Impl
 
     bool strokeCap(StrokeCap cap)
     {
-        if (!stroke) stroke = new ShapeStroke();
+        if (!stroke) stroke = static_cast<ShapeStroke*>(calloc(sizeof(ShapeStroke), 1));
         stroke->cap = cap;
         flag |= RenderUpdateFlag::Stroke;
 
@@ -278,7 +280,7 @@ struct Shape::Impl
 
     bool strokeJoin(StrokeJoin join)
     {
-        if (!stroke) stroke = new ShapeStroke();
+        if (!stroke) stroke = static_cast<ShapeStroke*>(calloc(sizeof(ShapeStroke), 1));
         stroke->join = join;
         flag |= RenderUpdateFlag::Stroke;
 
@@ -287,7 +289,7 @@ struct Shape::Impl
 
     bool strokeColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
     {
-        if (!stroke) stroke = new ShapeStroke();
+        if (!stroke) stroke = static_cast<ShapeStroke*>(calloc(sizeof(ShapeStroke), 1));
         if (stroke->fill) {
             delete(stroke->fill);
             stroke->fill = nullptr;
@@ -309,7 +311,7 @@ struct Shape::Impl
         auto p = f.release();
         if (!p) return Result::MemoryCorruption;
 
-        if (!stroke) stroke = new ShapeStroke();
+        if (!stroke) stroke = static_cast<ShapeStroke*>(calloc(sizeof(ShapeStroke), 1));
         if (stroke->fill && stroke->fill != p) delete(stroke->fill);
         stroke->fill = p;
 
@@ -326,7 +328,7 @@ struct Shape::Impl
             free(stroke->dashPattern);
             stroke->dashPattern = nullptr;
         } else {
-            if (!stroke) stroke = new ShapeStroke();
+            if (!stroke) stroke = static_cast<ShapeStroke*>(calloc(sizeof(ShapeStroke), 1));
             if (stroke->dashCnt != cnt) {
                 free(stroke->dashPattern);
                 stroke->dashPattern = nullptr;
@@ -363,7 +365,8 @@ struct Shape::Impl
 
         //Stroke
         if (stroke) {
-            dup->stroke = new ShapeStroke(stroke);
+            dup->stroke = static_cast<ShapeStroke*>(calloc(sizeof(ShapeStroke), 1));
+            dup->stroke->copy(stroke);
             dup->flag |= RenderUpdateFlag::Stroke;
 
             if (stroke->fill)