common array: ++enhance the usability.

+ end() which indicates the end of the data pointer.
This commit is contained in:
Hermet Park 2023-06-26 14:47:56 +09:00 committed by Hermet Park
parent bd87f1398c
commit 4482664740
4 changed files with 18 additions and 18 deletions

View file

@ -167,7 +167,7 @@ struct SwShapeTask : SwTask
shapeDelOutline(&shape, mpool, tid);
//Clip Path
for (auto clip = clips.data; clip < (clips.data + clips.count); ++clip) {
for (auto clip = clips.data; clip < clips.end(); ++clip) {
auto clipper = static_cast<SwTask*>(*clip);
//Clip shape rle
if (shape.rle && !clipper->clip(shape.rle)) goto err;
@ -228,7 +228,7 @@ struct SwSceneTask : SwTask
rleMerge(sceneRle, clipper1->rle(), clipper2->rle());
//Unify the remained clippers
for (auto rd = scene.data + 2; rd < (scene.data + scene.count); ++rd) {
for (auto rd = scene.data + 2; rd < scene.end(); ++rd) {
auto clipper = static_cast<SwTask*>(*rd);
rleMerge(sceneRle, sceneRle, clipper->rle());
}
@ -290,7 +290,7 @@ struct SwImageTask : SwTask
if (image.rle) {
//Clear current task memorypool here if the clippers would use the same memory pool
imageDelOutline(&image, mpool, tid);
for (auto clip = clips.data; clip < (clips.data + clips.count); ++clip) {
for (auto clip = clips.data; clip < clips.end(); ++clip) {
auto clipper = static_cast<SwTask*>(*clip);
if (!clipper->clip(image.rle)) goto err;
}
@ -367,7 +367,7 @@ SwRenderer::~SwRenderer()
bool SwRenderer::clear()
{
for (auto task = tasks.data; task < (tasks.data + tasks.count); ++task) {
for (auto task = tasks.data; task < tasks.end(); ++task) {
if ((*task)->disposed) {
delete(*task);
} else {
@ -440,7 +440,7 @@ bool SwRenderer::preRender()
void SwRenderer::clearCompositors()
{
//Free Composite Caches
for (auto comp = compositors.data; comp < (compositors.data + compositors.count); ++comp) {
for (auto comp = compositors.data; comp < compositors.end(); ++comp) {
free((*comp)->compositor->image.data);
delete((*comp)->compositor);
delete(*comp);
@ -456,7 +456,7 @@ bool SwRenderer::postRender()
rasterUnpremultiply(surface);
}
for (auto task = tasks.data; task < (tasks.data + tasks.count); ++task) {
for (auto task = tasks.data; task < tasks.end(); ++task) {
(*task)->pushed = false;
}
tasks.clear();
@ -613,7 +613,7 @@ Compositor* SwRenderer::target(const RenderRegion& region, ColorSpace cs)
auto reqChannelSize = CHANNEL_SIZE(cs);
//Use cached data
for (auto p = compositors.data; p < (compositors.data + compositors.count); ++p) {
for (auto p = compositors.data; p < compositors.end(); ++p) {
if ((*p)->compositor->valid && (*p)->compositor->image.channelSize == reqChannelSize) {
cmp = *p;
break;
@ -719,7 +719,7 @@ void* SwRenderer::prepareCommon(SwTask* task, const RenderTransform* transform,
//TODO: Failed threading them. It would be better if it's possible.
//See: https://github.com/thorvg/thorvg/issues/1409
//Guarantee composition targets get ready.
for (auto clip = clips.data; clip < (clips.data + clips.count); ++clip) {
for (auto clip = clips.data; clip < clips.end(); ++clip) {
static_cast<SwTask*>(*clip)->done();
}
@ -776,7 +776,7 @@ RenderData SwRenderer::prepare(const Array<RenderData>& scene, RenderData data,
//TODO: Failed threading them. It would be better if it's possible.
//See: https://github.com/thorvg/thorvg/issues/1409
//Guarantee composition targets get ready.
for (auto task = scene.data; task < (scene.data + scene.count); ++task) {
for (auto task = scene.data; task < scene.end(); ++task) {
static_cast<SwTask*>(*task)->done();
}
return prepareCommon(task, transform, clips, opacity, flags);

View file

@ -68,12 +68,12 @@ struct Array
return reserve(count + size);
}
T* ptr()
T* end() const
{
return data + count;
}
T* last()
T* last() const
{
return data + count - 1;
}

View file

@ -219,7 +219,7 @@ bool TvgSaver::writeHeader()
buffer.grow(headerSize);
//1. Signature
auto ptr = buffer.ptr();
auto ptr = buffer.end();
memcpy(ptr, TVG_HEADER_SIGNATURE, TVG_HEADER_SIGNATURE_LENGTH);
ptr += TVG_HEADER_SIGNATURE_LENGTH;
@ -244,7 +244,7 @@ bool TvgSaver::writeHeader()
void TvgSaver::writeTag(TvgBinTag tag)
{
buffer.grow(SIZE(TvgBinTag));
memcpy(buffer.ptr(), &tag, SIZE(TvgBinTag));
memcpy(buffer.end(), &tag, SIZE(TvgBinTag));
buffer.count += SIZE(TvgBinTag);
}
@ -252,14 +252,14 @@ void TvgSaver::writeTag(TvgBinTag tag)
void TvgSaver::writeCount(TvgBinCounter cnt)
{
buffer.grow(SIZE(TvgBinCounter));
memcpy(buffer.ptr(), &cnt, SIZE(TvgBinCounter));
memcpy(buffer.end(), &cnt, SIZE(TvgBinCounter));
buffer.count += SIZE(TvgBinCounter);
}
void TvgSaver::writeReservedCount(TvgBinCounter cnt)
{
memcpy(buffer.ptr() - cnt - SIZE(TvgBinCounter), &cnt, SIZE(TvgBinCounter));
memcpy(buffer.end() - cnt - SIZE(TvgBinCounter), &cnt, SIZE(TvgBinCounter));
}
@ -273,7 +273,7 @@ void TvgSaver::reserveCount()
TvgBinCounter TvgSaver::writeData(const void* data, TvgBinCounter cnt)
{
buffer.grow(cnt);
memcpy(buffer.ptr(), data, cnt);
memcpy(buffer.end(), data, cnt);
buffer.count += cnt;
return cnt;
@ -286,7 +286,7 @@ TvgBinCounter TvgSaver::writeTagProperty(TvgBinTag tag, TvgBinCounter cnt, const
buffer.grow(growCnt);
auto ptr = buffer.ptr();
auto ptr = buffer.end();
*ptr = tag;
++ptr;

View file

@ -189,7 +189,7 @@ public:
mBounds[0], mBounds[1] + mBounds[3], //(x1, y2)
};
for (auto paint = parents.data; paint < (parents.data + parents.count); ++paint) {
for (auto paint = parents.data; paint < parents.end(); ++paint) {
auto m = const_cast<Paint*>(*paint)->transform();
for (int i = 0; i<8; i += 2) {
float x = points[i] * m.e11 + points[i+1] * m.e12 + m.e13;