From: Mikko Rasa Date: Wed, 21 Dec 2022 09:48:44 +0000 (+0200) Subject: Replace some sets with vectors as well X-Git-Url: http://git.tdb.fi/?p=builder.git;a=commitdiff_plain;h=fefa7d1e8ac40136b690e305ce9594af95c678b8 Replace some sets with vectors as well In these cases the number of expected elements is small and/or the set is built up once and then used many times. --- diff --git a/source/androidapplicationcomponent.cpp b/source/androidapplicationcomponent.cpp index 212db7d..1aab735 100644 --- a/source/androidapplicationcomponent.cpp +++ b/source/androidapplicationcomponent.cpp @@ -1,3 +1,4 @@ +#include #include #include #include "androidapplicationcomponent.h" @@ -91,5 +92,6 @@ AndroidApplicationComponent::Loader::Loader(AndroidApplicationComponent &c): void AndroidApplicationComponent::Loader::permission(const string &perm) { - obj.permissions.insert(perm); + if(!any_equals(obj.permissions, perm)) + obj.permissions.push_back(perm); } diff --git a/source/androidapplicationcomponent.h b/source/androidapplicationcomponent.h index 017467f..c791a74 100644 --- a/source/androidapplicationcomponent.h +++ b/source/androidapplicationcomponent.h @@ -1,7 +1,6 @@ #ifndef ANDROIDAPPLICATIONCOMPONENT_H_ #define ANDROIDAPPLICATIONCOMPONENT_H_ -#include #include "component.h" class AndroidApplicationComponent: public Component @@ -18,7 +17,7 @@ public: private: std::string orientation; - std::set permissions; + std::vector permissions; public: AndroidApplicationComponent(SourcePackage &, const std::string &); diff --git a/source/androidassetpackagingtool.cpp b/source/androidassetpackagingtool.cpp index 3d86747..af8bc95 100644 --- a/source/androidassetpackagingtool.cpp +++ b/source/androidassetpackagingtool.cpp @@ -1,3 +1,4 @@ +#include #include #include "androidassetpackagingtool.h" #include "androidmanifestfile.h" @@ -77,17 +78,17 @@ Task *AndroidAssetPackagingTool::run(const Target &tgt) const else if(real->get_package()==res.get_package()) { const FS::Path &path = file->get_path(); - resource_dirs.push_back(path.subpath(0, path.size()-2)); + FS::Path res_dir = path.subpath(0, path.size()-2); + if(!any_equals(resource_dirs, res_dir)) + resource_dirs.push_back(res_dir); } } - set seen_dirs; for(const FS::Path &d: resource_dirs) - if(seen_dirs.insert(d.str()).second) - { - argv.push_back("-S"); - argv.push_back(FS::relative(d, work_dir).str()); - } + { + argv.push_back("-S"); + argv.push_back(FS::relative(d, work_dir).str()); + } return new ExternalTask(argv, work_dir); } diff --git a/source/androidmanifestfile.cpp b/source/androidmanifestfile.cpp index d20be98..527bfac 100644 --- a/source/androidmanifestfile.cpp +++ b/source/androidmanifestfile.cpp @@ -1,9 +1,11 @@ +#include #include "androidapplicationcomponent.h" #include "androidmanifestfile.h" #include "builder.h" #include "sourcepackage.h" using namespace std; +using namespace Msp; AndroidManifestFile::AndroidManifestFile(Builder &b, const AndroidApplicationComponent &a): FileTarget(b, a.get_package(), a.get_package().get_temp_directory()/a.get_name()/"AndroidManifest.xml"), @@ -27,5 +29,6 @@ void AndroidManifestFile::set_orientation(const string &ori) void AndroidManifestFile::add_permission(const string &perm) { - permissions.insert(perm); + if(!any_equals(permissions, perm)) + permissions.push_back(perm); } diff --git a/source/androidmanifestfile.h b/source/androidmanifestfile.h index 8f1af50..cd02df0 100644 --- a/source/androidmanifestfile.h +++ b/source/androidmanifestfile.h @@ -1,7 +1,7 @@ #ifndef ANDROIDMANIFESTFILE_H_ #define ANDROIDMANIFESTFILE_H_ -#include +#include #include "filetarget.h" class AndroidApplicationComponent; @@ -14,7 +14,7 @@ class AndroidManifestFile: public FileTarget { private: SharedLibrary *native_lib; - std::set permissions; + std::vector permissions; std::string orientation; public: @@ -27,7 +27,7 @@ public: void add_permission(const std::string &); void set_orientation(const std::string &); - const std::set &get_permissions() const { return permissions; } + const std::vector &get_permissions() const { return permissions; } const std::string &get_orientation() const { return orientation; } }; diff --git a/source/buildinfo.cpp b/source/buildinfo.cpp index 43e1427..8ca9af8 100644 --- a/source/buildinfo.cpp +++ b/source/buildinfo.cpp @@ -1,4 +1,3 @@ -#include #include #include #include "buildinfo.h" diff --git a/source/logger.cpp b/source/logger.cpp index 901800e..dfb5fd4 100644 --- a/source/logger.cpp +++ b/source/logger.cpp @@ -1,3 +1,4 @@ +#include #include #include "logger.h" @@ -6,16 +7,21 @@ using namespace Msp; void Logger::enable_channel(const string &chan) { - enabled_channels.insert(chan); + auto i = lower_bound(enabled_channels, chan); + if(i==enabled_channels.end() || *i!=chan) + enabled_channels.insert(i, chan); } void Logger::disable_channel(const string &chan) { - enabled_channels.erase(chan); + auto i = lower_bound(enabled_channels, chan); + if(i!=enabled_channels.end() && *i==chan) + enabled_channels.erase(i); } void Logger::log(const string &chan, const string &message) const { - if(enabled_channels.count(chan)) + auto i = lower_bound(enabled_channels, chan); + if(i!=enabled_channels.end() && *i==chan) IO::print("%s\n", message); } diff --git a/source/logger.h b/source/logger.h index c22339f..64c1315 100644 --- a/source/logger.h +++ b/source/logger.h @@ -1,13 +1,13 @@ #ifndef LOGGER_H_ #define LOGGER_H_ -#include #include +#include class Logger { private: - std::set enabled_channels; + std::vector enabled_channels; public: void enable_channel(const std::string &); diff --git a/source/packagemanager.h b/source/packagemanager.h index a2c684e..d5cfb52 100644 --- a/source/packagemanager.h +++ b/source/packagemanager.h @@ -2,6 +2,7 @@ #define PACKAGEMANAGER_H_ #include +#include #include #include #include