mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Hoist the getting of the XSLT style-sheet out of the loop
We don't need to get it for every file, since it's the same. This also avoids leaking temporary files and memory if the stylesheet cannot be found. Signed-off-by: Thiago Macieira <thiago@macieira.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
a17880ca02
commit
04ec3cf31f
1 changed files with 7 additions and 8 deletions
|
@ -118,6 +118,12 @@ static char *prepare_dives_for_divelogs(const bool selected)
|
|||
struct zip_source *s[dive_table.nr];
|
||||
struct zip *zip;
|
||||
|
||||
xslt = get_stylesheet("divelogs-export.xslt");
|
||||
if (!xslt) {
|
||||
qDebug() << errPrefix << "missing stylesheet";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* generate a random filename and create/open that file with zip_open */
|
||||
QString tempfileQ = QDir::tempPath() + "/import-" + QString::number(qrand() % 99999999) + ".dld";
|
||||
tempfile = strdup(tempfileQ.toLocal8Bit().data());
|
||||
|
@ -166,15 +172,7 @@ static char *prepare_dives_for_divelogs(const bool selected)
|
|||
return NULL;
|
||||
}
|
||||
free((void *)membuf);
|
||||
// this call is overriding our local variable tempfile! not a good sign!
|
||||
xslt = get_stylesheet("divelogs-export.xslt");
|
||||
if (!xslt) {
|
||||
qDebug() << errPrefix << "missing stylesheet";
|
||||
free((void *)tempfile);
|
||||
return NULL;
|
||||
}
|
||||
transformed = xsltApplyStylesheet(xslt, doc, NULL);
|
||||
xsltFreeStylesheet(xslt);
|
||||
xmlDocDumpMemory(transformed, (xmlChar **) &membuf, (int *)&streamsize);
|
||||
xmlFreeDoc(doc);
|
||||
xmlFreeDoc(transformed);
|
||||
|
@ -190,6 +188,7 @@ static char *prepare_dives_for_divelogs(const bool selected)
|
|||
}
|
||||
}
|
||||
zip_close(zip);
|
||||
xsltFreeStylesheet(xslt);
|
||||
return tempfile;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue