diff options
author | Giuseppe D'Angelo <[email protected]> | 2019-06-10 15:57:52 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <[email protected]> | 2019-12-14 11:31:46 +0100 |
commit | 5b4b437b30b320e2cd7c9a566999a39772e5d431 (patch) | |
tree | bfaf7959a37e840ee886d0471134a133eefc7685 /util/gradientgen/tobinaryjson.cpp | |
parent | 4522b17159a29ffd12c4d93be8a6e8e1a05dccd0 (diff) |
WebGradients: redo implementation
The previous implementation was *extremely* expensive. It
relied on loading a binary JSON file from resources (which
involved decompressing it), then extracting information out of
it to build a gradient. Already-loaded gradients were kept in
a local cache, which had to be mutex protected.
Instead, this patch extends the gradient generator to build
static arrays filled with the web gradient data, sitting in
.rodata.
These arrays are used when building QGradient objects with a
web gradient. No explicit mutex protection is necessary, since
accesses will just read from the arrays.
As benefits, this patch removes:
* the binary json representation from QtGui's resources (~4KB
compressed, ~50KB uncompressed)
* the overhead of reading from the JSON for each used web
gradient;
* the startup costs of registering the webgradients in the
resources;
* all the overhead of mutex locking when building such
gradients;
* all the runtime memory allocations to load, parse and cache
the web gradients (including the memory + CPU spike on first
load due to the uncompression of the JSON data, as well as a
couple of deep copies).
Change-Id: If5c3d704430df76ce8faf55ee75ebd4639ba09c4
Reviewed-by: Tor Arne Vestbø <[email protected]>
Reviewed-by: Ulf Hermann <[email protected]>
Reviewed-by: Qt CI Bot <[email protected]>
Reviewed-by: Thiago Macieira <[email protected]>
Reviewed-by: Edward Welbourne <[email protected]>
Diffstat (limited to 'util/gradientgen/tobinaryjson.cpp')
-rw-r--r-- | util/gradientgen/tobinaryjson.cpp | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/util/gradientgen/tobinaryjson.cpp b/util/gradientgen/tobinaryjson.cpp deleted file mode 100644 index 65fe07f4b83..00000000000 --- a/util/gradientgen/tobinaryjson.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the utils of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <iostream> - -#include <qdebug.h> -#include <qjsondocument.h> - -using namespace std; - -int main() -{ - QByteArray json; - while (!cin.eof()) { - char arr[1024]; - cin.read(arr, sizeof(arr)); - json.append(arr, cin.gcount()); - } - - QJsonParseError error; - QJsonDocument document = QJsonDocument::fromJson(json, &error); - if (document.isNull()) { - qDebug() << "error:" << qPrintable(error.errorString()) << "at offset" << error.offset; - return 1; - } - - QByteArray binaryJson = document.toBinaryData(); - cout.write(binaryJson.constData(), binaryJson.size()); -} |