Changed reverse shape list to tail cached variant

This commit is contained in:
daniel-starke 2017-04-21 22:05:26 +02:00
parent 3f40cbc53e
commit 096f60a5c5

View File

@ -435,6 +435,7 @@ typedef struct NSVGparser
NSVGpath* plist; NSVGpath* plist;
NSVGimage* image; NSVGimage* image;
NSVGgradientData* gradients; NSVGgradientData* gradients;
NSVGshape* shapesTail;
float viewMinx, viewMiny, viewWidth, viewHeight; float viewMinx, viewMiny, viewWidth, viewHeight;
int alignX, alignY, alignType; int alignX, alignY, alignType;
float dpi; float dpi;
@ -996,9 +997,12 @@ static void nsvg__addShape(NSVGparser* p)
// Set flags // Set flags
shape->flags = (attr->visible ? NSVG_FLAGS_VISIBLE : 0x00); shape->flags = (attr->visible ? NSVG_FLAGS_VISIBLE : 0x00);
// Add to head due to performance, reverse list later // Add to tail
shape->next = p->image->shapes; if (p->image->shapes == NULL)
p->image->shapes = shape; p->image->shapes = shape;
else
p->shapesTail->next = shape;
p->shapesTail = shape;
return; return;
@ -2787,7 +2791,6 @@ NSVGimage* nsvgParse(char* input, const char* units, float dpi)
{ {
NSVGparser* p; NSVGparser* p;
NSVGimage* ret = 0; NSVGimage* ret = 0;
NSVGshape* cur, *prev, *tmp;
p = nsvg__createParser(); p = nsvg__createParser();
if (p == NULL) { if (p == NULL) {
@ -2797,17 +2800,6 @@ NSVGimage* nsvgParse(char* input, const char* units, float dpi)
nsvg__parseXML(input, nsvg__startElement, nsvg__endElement, nsvg__content, p); nsvg__parseXML(input, nsvg__startElement, nsvg__endElement, nsvg__content, p);
// Reverse the list of shapes to match SVG order
cur = p->image->shapes;
prev = NULL;
while (cur != NULL) {
tmp = cur;
cur = cur->next;
tmp->next = prev;
prev = tmp;
}
if (prev != NULL) p->image->shapes = prev;
// Scale to viewBox // Scale to viewBox
nsvg__scaleToViewbox(p, units); nsvg__scaleToViewbox(p, units);