diff options
author | Luca Di Sera <luca.disera@qt.io> | 2023-03-24 11:38:09 +0100 |
---|---|---|
committer | Luca Di Sera <luca.disera@qt.io> | 2023-03-27 12:44:45 +0200 |
commit | 2a3f531028e8c59a745d3fb90aecbed18cd759dd (patch) | |
tree | 6d5c0918a832e302fd5f54c14c155dc6d2e074c9 | |
parent | 3e67f3d5538522efebf99855c1cd7c2eca3f61f9 (diff) | |
download | qttools-2a3f531028e8c59a745d3fb90aecbed18cd759dd.tar.gz |
QDoc: Flatten maps of source file in "main.cpp"
When QDoc runs it collects a series of input source files based on
certain configuration variables.
The collected input source files are later used as the base for
extracting the user-provided documentation.
The files are collected into a map, in `processQDocConfFile`,
`sources`.
The map uses the same values, file paths that QDoc extracted from the
above mentioned configuration variables, for each key-value pair.
That is, given a file path X, `sources` stores a key-value pair X-X.
Supposedly, the intention of using a map was to avoid duplicates.
Indeed, the code that populates the map avoid inserting elements that
already are present in the map, thus making use of the fast lookup that
the data structure provides.
As half of the map is left unused, indeed only the keys are ever
accessed, we replace the map with a set, which better provides the
required removal of duplicates.
Change-Id: If4de2f1a6c8b45ac138139b7d49b1d0d73ed2c1f
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
-rw-r--r-- | src/qdoc/main.cpp | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/src/qdoc/main.cpp b/src/qdoc/main.cpp index fdf4ba79f..5b301b3c1 100644 --- a/src/qdoc/main.cpp +++ b/src/qdoc/main.cpp @@ -27,6 +27,8 @@ #include <QtCore/qglobal.h> #include <QtCore/qhashfunctions.h> +#include <set> + #ifndef QT_BOOTSTRAPPED # include <QtCore/qcoreapplication.h> #endif @@ -45,9 +47,9 @@ bool creationTimeBefore(const QFileInfo &fi1, const QFileInfo &fi2) /*! \internal - Iterate over a map of \a source file paths. Known source file types are - parsed to extract user-provided documentation and information about source - code level elements. + Inspects each file path in \a sources. File paths with a known + source file type are parsed to extract user-provided + documentation and information about source code level elements. \note Unknown source file types are silently ignored. @@ -57,16 +59,15 @@ bool creationTimeBefore(const QFileInfo &fi1, const QFileInfo &fi2) \sa CodeParser::parserForSourceFile, CodeParser::sourceFileNameFilter */ -static void parseSourceFiles(const QMap<QString, QString> &sources) +static void parseSourceFiles(const std::set<QString> &sources) { CppCodeParser cpp_code_parser{}; - for (auto it = sources.cbegin(), end = sources.cend(); it != end; ++it) { - const auto &key = it.key(); - auto *codeParser = CodeParser::parserForSourceFile(key); - if (!codeParser) - continue; - qCDebug(lcQdoc, "Parsing %s", qPrintable(key)); - codeParser->parseSourceFile(Config::instance().location(), key, cpp_code_parser); + for (const QString& source_file_path : sources) { + auto *codeParser = CodeParser::parserForSourceFile(source_file_path); + if (!codeParser) continue; + + qCDebug(lcQdoc, "Parsing %s", qPrintable(source_file_path)); + codeParser->parseSourceFile(Config::instance().location(), source_file_path, cpp_code_parser); } } @@ -478,13 +479,11 @@ static void processQdocconfFile(const QString &fileName) qCDebug(lcQdoc, "Reading sourcedirs"); sourceList = config.getAllFiles(CONFIG_SOURCES, CONFIG_SOURCEDIRS, excludedDirs, excludedFiles); - QMap<QString, QString> sources; + std::set<QString> sources{}; for (const auto &source : sourceList) { if (source.contains(QLatin1String("doc/snippets"))) continue; - if (sources.contains(source)) - continue; - sources.insert(source, source); + sources.emplace(source); } /* Find all the qdoc files in the example dirs, and add @@ -493,9 +492,7 @@ static void processQdocconfFile(const QString &fileName) qCDebug(lcQdoc, "Reading exampledirs"); QStringList exampleQdocList = config.getExampleQdocFiles(excludedDirs, excludedFiles); for (const auto &example : exampleQdocList) { - if (!sources.contains(example)) { - sources.insert(example, example); - } + sources.emplace(example); } /* Parse each header file in the set using the appropriate parser and add it |