mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-10 06:34:01 +00:00
binary size optimization.
replaced new/delete with malloc/free saved 936 bytes
This commit is contained in:
parent
b289950a5f
commit
eadb7fc4af
7 changed files with 41 additions and 36 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -31,22 +31,21 @@
|
|||
|
||||
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;
|
||||
float width;
|
||||
uint8_t color[4];
|
||||
Fill *fill;
|
||||
float* dashPattern;
|
||||
uint32_t dashCnt;
|
||||
StrokeCap cap;
|
||||
StrokeJoin join;
|
||||
|
||||
ShapeStroke() {}
|
||||
|
||||
ShapeStroke(const ShapeStroke* src)
|
||||
: width(src->width),
|
||||
dashCnt(src->dashCnt),
|
||||
cap(src->cap),
|
||||
join(src->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)
|
||||
|
|
Loading…
Add table
Reference in a new issue