Commit 1a8f5876 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Flatpak: Reduce memory allocations

Use a regex instead of writing a configuration file to disk to have it
parsed.
parent 5e77a146
......@@ -57,6 +57,7 @@
#include <QNetworkAccessManager>
#include <glib.h>
#include <QRegularExpression>
#include "FlatpakSourcesBackend.h"
DISCOVER_BACKEND_PLUGIN(FlatpakBackend)
......@@ -929,21 +930,14 @@ bool FlatpakBackend::updateAppMetadata(FlatpakResource *resource, const QString
bool FlatpakBackend::updateAppMetadata(FlatpakResource *resource, const QByteArray &data)
{
// Save the content to temporary file
QTemporaryFile tempFile;
tempFile.setAutoRemove(false);
if (!tempFile.open()) {
qWarning() << "Failed to get metadata file";
//We just find the runtime with a regex, QSettings only can read from disk (and so does KConfig)
const QRegularExpression rx(QStringLiteral("runtime=(.*)"));
const auto match = rx.match(QString::fromUtf8(data));
if (!match.isValid()) {
return false;
}
tempFile.write(data);
tempFile.close();
updateAppMetadata(resource, tempFile.fileName());
tempFile.remove();
resource->setRuntime(match.captured(1));
return true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment