]> git.tdb.fi Git - builder.git/commitdiff
Replace some sets with vectors as well
authorMikko Rasa <tdb@tdb.fi>
Wed, 21 Dec 2022 09:48:44 +0000 (11:48 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 21 Dec 2022 11:59:39 +0000 (13:59 +0200)
In these cases the number of expected elements is small and/or the set
is built up once and then used many times.

source/androidapplicationcomponent.cpp
source/androidapplicationcomponent.h
source/androidassetpackagingtool.cpp
source/androidmanifestfile.cpp
source/androidmanifestfile.h
source/buildinfo.cpp
source/logger.cpp
source/logger.h
source/packagemanager.h

index 212db7d5df08755bdb68a610d22c5ecacfc0095f..1aab7355009444a8e98c6c136b9232e633a9c90c 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/algorithm.h>
 #include <msp/fs/utils.h>
 #include <msp/strings/format.h>
 #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);
 }
index 017467f20df897a9a58399d550c6065ae4ce93d0..c791a74861b6b992fb8d86483ea4aea0cb63039a 100644 (file)
@@ -1,7 +1,6 @@
 #ifndef ANDROIDAPPLICATIONCOMPONENT_H_
 #define ANDROIDAPPLICATIONCOMPONENT_H_
 
-#include <set>
 #include "component.h"
 
 class AndroidApplicationComponent: public Component
@@ -18,7 +17,7 @@ public:
 
 private:
        std::string orientation;
-       std::set<std::string> permissions;
+       std::vector<std::string> permissions;
 
 public:
        AndroidApplicationComponent(SourcePackage &, const std::string &);
index 3d867472d6c2699302623d5edac52df6559642fc..af8bc95ea422187112d5dce75927d8567803d309 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/algorithm.h>
 #include <msp/fs/utils.h>
 #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<string> 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);
 }
index d20be983167cd7e6e492e786c67443e2e542a86f..527bfac874c59a2657d48c3c446d6e8de23b48e6 100644 (file)
@@ -1,9 +1,11 @@
+#include <msp/core/algorithm.h>
 #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);
 }
index 8f1af504373dda15a68251cc895b780a39655d6d..cd02df0a452031b259a9d87c837341c076a6a102 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef ANDROIDMANIFESTFILE_H_
 #define ANDROIDMANIFESTFILE_H_
 
-#include <set>
+#include <vector>
 #include "filetarget.h"
 
 class AndroidApplicationComponent;
@@ -14,7 +14,7 @@ class AndroidManifestFile: public FileTarget
 {
 private:
        SharedLibrary *native_lib;
-       std::set<std::string> permissions;
+       std::vector<std::string> 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<std::string> &get_permissions() const { return permissions; }
+       const std::vector<std::string> &get_permissions() const { return permissions; }
        const std::string &get_orientation() const { return orientation; }
 };
 
index 43e1427df6a1cc3cea3a6ae1cd1acec6129d2ac5..8ca9af8dd136dca3812f2f8da9f38fc7c4e0e8f0 100644 (file)
@@ -1,4 +1,3 @@
-#include <set>
 #include <msp/core/algorithm.h>
 #include <msp/strings/format.h>
 #include "buildinfo.h"
index 901800ec30fc2736113227988cc480f25a722d45..dfb5fd4d6ced799be4a3f4aad4aaf43d60631c5e 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/algorithm.h>
 #include <msp/io/print.h>
 #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);
 }
index c22339f55928270dacadccc02fb2c27302b85b42..64c131544c4cef1995ec8c8b3786b7355f90ee36 100644 (file)
@@ -1,13 +1,13 @@
 #ifndef LOGGER_H_
 #define LOGGER_H_
 
-#include <set>
 #include <string>
+#include <vector>
 
 class Logger
 {
 private:
-       std::set<std::string> enabled_channels;
+       std::vector<std::string> enabled_channels;
 
 public:
        void enable_channel(const std::string &);
index a2c684e0bfd7796f487b2185f20f0658bdbdc71d..d5cfb52e51d5b8493e4adc9d2caf7e4e0319b622 100644 (file)
@@ -2,6 +2,7 @@
 #define PACKAGEMANAGER_H_
 
 #include <map>
+#include <set>
 #include <string>
 #include <vector>
 #include <msp/fs/path.h>