]> git.tdb.fi Git - libs/core.git/commitdiff
Prefer more cache-efficient containers
authorMikko Rasa <tdb@tdb.fi>
Sun, 29 Aug 2021 13:16:44 +0000 (16:16 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 29 Aug 2021 22:42:03 +0000 (01:42 +0300)
source/core/getopt.cpp
source/core/getopt.h
source/debug/backtrace.h
source/fs/dir.cpp
source/fs/dir.h
source/fs/unix/utils.cpp
source/fs/utils.cpp
source/strings/regex.cpp

index ec821e0d26aea1372c3314cc8a1a99a268d5443e..6f7b1f807c9d719d3829959db91370860a62fabe 100644 (file)
@@ -260,7 +260,7 @@ string GetOpt::generate_help() const
        bool any_short = any_of(opts.begin(), opts.end(), [](const OptionImpl *o){ return o->get_short(); });
 
        string::size_type maxw = 0;
        bool any_short = any_of(opts.begin(), opts.end(), [](const OptionImpl *o){ return o->get_short(); });
 
        string::size_type maxw = 0;
-       list<string> switches;
+       vector<string> switches;
        for(const OptionImpl *o: opts)
        {
                string swtch;
        for(const OptionImpl *o: opts)
        {
                string swtch;
@@ -289,7 +289,7 @@ string GetOpt::generate_help() const
                maxw = max(maxw, swtch.size());
        }
 
                maxw = max(maxw, swtch.size());
        }
 
-       list<string> pargs;
+       vector<string> pargs;
        for(const ArgumentImpl *a: args)
        {
                string parg = format("<%s>", a->get_name());
        for(const ArgumentImpl *a: args)
        {
                string parg = format("<%s>", a->get_name());
index 27ce4cf2fdb05824b3834eb0d972a7192ec3a1fd..405864bb27bfdda1668537a35630550465963482 100644 (file)
@@ -204,8 +204,8 @@ private:
        };
 
        bool help;
        };
 
        bool help;
-       std::list<OptionImpl *> opts;
-       std::list<ArgumentImpl *> args;
+       std::vector<OptionImpl *> opts;
+       std::vector<ArgumentImpl *> args;
        std::vector<std::string> args_raw;
 
 public:
        std::vector<std::string> args_raw;
 
 public:
index 33ed8934eb1fd966b09664eb6cbe5c046eeeef8a..3f32ade0c4558478f633e93f02f9e9e29b261024 100644 (file)
@@ -1,9 +1,9 @@
 #ifndef MSP_DEBUG_BACKTRACE_H_
 #define MSP_DEBUG_BACKTRACE_H_
 
 #ifndef MSP_DEBUG_BACKTRACE_H_
 #define MSP_DEBUG_BACKTRACE_H_
 
-#include <list>
 #include <ostream>
 #include <string>
 #include <ostream>
 #include <string>
+#include <vector>
 
 namespace Msp {
 namespace Debug {
 
 namespace Msp {
 namespace Debug {
@@ -19,10 +19,10 @@ public:
        };
 
 private:
        };
 
 private:
-       std::list<StackFrame> frames;
+       std::vector<StackFrame> frames;
 
 public:
 
 public:
-       const std::list<StackFrame> &get_frames() const { return frames; }
+       const std::vector<StackFrame> &get_frames() const { return frames; }
 
        static Backtrace create();
 };
 
        static Backtrace create();
 };
index 99de180d20ed026812e7fcb2e371dc843a0c333f..098020328342db2edf93d4b2b425555405ab5f00 100644 (file)
@@ -101,16 +101,16 @@ void rmpath(const Path &path)
        rmdir(path);
 }
 
        rmdir(path);
 }
 
-list<string> list_files(const Path &path)
+vector<string> list_files(const Path &path)
 {
        return list_filtered(path, string());
 }
 
 {
        return list_filtered(path, string());
 }
 
-list<string> list_filtered(const Path &path, const string &filter)
+vector<string> list_filtered(const Path &path, const string &filter)
 {
        Regex r_filter(filter);
 
 {
        Regex r_filter(filter);
 
-       list<string> result;
+       vector<string> result;
        DIR *dir = opendir(path.str().c_str());
        if(!dir)
                throw system_error("opendir");
        DIR *dir = opendir(path.str().c_str());
        if(!dir)
                throw system_error("opendir");
@@ -177,7 +177,7 @@ Path get_sys_lib_dir()
                return dir;
 }
 
                return dir;
 }
 
-Path path_lookup(const string &name, const list<Path> &paths)
+Path path_lookup(const string &name, const vector<Path> &paths)
 {
        for(const Path &p: paths)
        {
 {
        for(const Path &p: paths)
        {
@@ -192,8 +192,8 @@ Path path_lookup(const string &name, const list<Path> &paths)
 Path path_lookup(const string &name)
 {
        const char *path = getenv("PATH");
 Path path_lookup(const string &name)
 {
        const char *path = getenv("PATH");
-       list<string> dirs = split(path, ITEMSEP);
-       return path_lookup(name, list<Path>(dirs.begin(), dirs.end()));
+       vector<string> dirs = split(path, ITEMSEP);
+       return path_lookup(name, vector<Path>(dirs.begin(), dirs.end()));
 }
 
 } // namespace FS
 }
 
 } // namespace FS
index be5fac8662533b908cd720059e25deece28a81f4..c0a1c7460324f3163715d5c119b0fea701b3517e 100644 (file)
@@ -1,9 +1,9 @@
 #ifndef MSP_FS_DIR_H_
 #define MSP_FS_DIR_H_
 
 #ifndef MSP_FS_DIR_H_
 #define MSP_FS_DIR_H_
 
-#include <list>
 #include <stdexcept>
 #include <string>
 #include <stdexcept>
 #include <string>
+#include <vector>
 #include "path.h"
 
 namespace Msp {
 #include "path.h"
 
 namespace Msp {
@@ -29,10 +29,10 @@ void rmdir(const Path &path);
 void rmpath(const Path &path);
 
 /// Lists the contents of a directory
 void rmpath(const Path &path);
 
 /// Lists the contents of a directory
-std::list<std::string> list_files(const Path &path);
+std::vector<std::string> list_files(const Path &path);
 
 /// Lists the contents of a directory, filtered with a regex
 
 /// Lists the contents of a directory, filtered with a regex
-std::list<std::string> list_filtered(const Path &path, const std::string &filter);
+std::vector<std::string> list_filtered(const Path &path, const std::string &filter);
 
 /// Returns the current working directory
 Path getcwd();
 
 /// Returns the current working directory
 Path getcwd();
@@ -57,7 +57,7 @@ Path get_sys_lib_dir();
 
 /** Looks for a file in a list of paths.  Returns the absolute path to the
 first existing location, or an empty Path if the file is not found at all. */
 
 /** Looks for a file in a list of paths.  Returns the absolute path to the
 first existing location, or an empty Path if the file is not found at all. */
-Path path_lookup(const std::string &, const std::list<Path> &);
+Path path_lookup(const std::string &, const std::vector<Path> &);
 
 /** Looks for a file using the PATH environment variable. */
 Path path_lookup(const std::string &);
 
 /** Looks for a file using the PATH environment variable. */
 Path path_lookup(const std::string &);
index c832343f76e822bacf4184ddc11379f750ee950d..a960b4051d3e59e283137b7490be2517ccdb6113 100644 (file)
@@ -1,4 +1,5 @@
 #include <cstdio>
 #include <cstdio>
+#include <deque>
 #include <unistd.h>
 #include <msp/core/systemerror.h>
 #include "dir.h"
 #include <unistd.h>
 #include <msp/core/systemerror.h>
 #include "dir.h"
@@ -21,7 +22,7 @@ Path readlink(const Path &link)
 
 Path realpath(const Path &path)
 {
 
 Path realpath(const Path &path)
 {
-       list<string> queue(path.begin(), path.end());
+       deque<string> queue(path.begin(), path.end());
        if(!path.is_absolute())
        {
                Path cwd = getcwd();
        if(!path.is_absolute())
        {
                Path cwd = getcwd();
index e15aad4d7b8b63980e45f9b514e16f22e57ec3e7..7ceb7adae843e149c3c05dd6d464d9b2e0bd9396 100644 (file)
@@ -49,7 +49,7 @@ Path fix_case(const Path &path)
                        result /= c;
                else
                {
                        result /= c;
                else
                {
-                       list<string> files;
+                       vector<string> files;
                        if(result.size())
                                files = list_files(result);
                        else
                        if(result.size())
                                files = list_files(result);
                        else
index 9167c6b8a9e6ae0f75fd52206bb96efe45a9424b..27361b038b168071cabd98aa45a37e37fb27d9cc 100644 (file)
@@ -1,6 +1,7 @@
 #include <limits>
 #include <list>
 #include <stack>
 #include <limits>
 #include <list>
 #include <stack>
+#include <vector>
 #include "format.h"
 #include "regex.h"
 
 #include "format.h"
 #include "regex.h"
 
@@ -157,7 +158,7 @@ Regex::Code Regex::compile(const string &expr, string::const_iterator &iter, uns
        }
        else
        {
        }
        else
        {
-               list<Code> branches;
+               vector<Code> branches;
                for(auto i=iter;;)
                {
                        branches.push_back(compile(expr, i, group, true));
                for(auto i=iter;;)
                {
                        branches.push_back(compile(expr, i, group, true));