]> git.tdb.fi Git - builder.git/blobdiff - source/buildinfo.cpp
Replace some sets with vectors as well
[builder.git] / source / buildinfo.cpp
index 1cafbd3b866344d2665181393b7e1fa0855ea197..8ca9af8dd136dca3812f2f8da9f38fc7c4e0e8f0 100644 (file)
@@ -1,5 +1,4 @@
-#include <algorithm>
-#include <set>
+#include <msp/core/algorithm.h>
 #include <msp/strings/format.h>
 #include "buildinfo.h"
 
@@ -8,18 +7,19 @@ using namespace Msp;
 
 namespace {
 
-/** Removes any duplicate entries from a list, leaving only the first one.  The
-order of other elements is preserved.  O(nlogn) efficiency. */
+/** Removes any duplicate entries from a vector, leaving only the first one.
+The order of other elements is preserved. */
 template<typename T>
-void unique(list<T> &l)
+void unique(vector<T> &v)
 {
-       set<T> seen;
-       for(typename list<T>::iterator i=l.begin(); i!=l.end(); )
+       vector<T> seen;
+       for(auto i=v.begin(); i!=v.end(); )
        {
-               if(seen.count(*i))
-                       l.erase(i++);
+               auto j = lower_bound(seen, *i);
+               if(j!=seen.end() && *j==*i)
+                       i = v.erase(i);
                else
-                       seen.insert(*i++);
+                       seen.insert(j, *i++);
        }
 }
 
@@ -39,7 +39,7 @@ BuildInfo::BuildInfo():
 
 BuildInfo::LibraryMode BuildInfo::get_libmode_for(const string &lib) const
 {
-       LibModeMap::const_iterator i = libmodes.find(lib);
+       auto i = libmodes.find(lib);
        if(i!=libmodes.end())
                return i->second;
        return libmode;
@@ -47,12 +47,24 @@ BuildInfo::LibraryMode BuildInfo::get_libmode_for(const string &lib) const
 
 void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level)
 {
-       for(DefineMap::const_iterator i=bi.defines.begin(); i!=bi.defines.end(); ++i)
-               defines[i->first] = i->second;
+       for(const auto &kvp: bi.defines)
+               defines[kvp.first] = kvp.second;
        incpath.insert(incpath.begin(), bi.incpath.begin(), bi.incpath.end());
        threads = bi.threads;
-       for(StandardMap::const_iterator i=bi.standards.begin(); i!=bi.standards.end(); ++i)
-               standards[i->first] = i->second;
+
+       for(const auto &kvp: bi.standards)
+       {
+               auto j = standards.find(kvp.first);
+               if(j==standards.end())
+                       standards.insert(kvp);
+               else if(kvp.second.type!=j->second.type || kvp.second.year!=j->second.year)
+               {
+                       if(!kvp.second.type.compare(0, 3, "gnu"))
+                               j->second.type = kvp.second.type;
+                       if(kvp.second.year>j->second.year)
+                               j->second.year = kvp.second.year;
+               }
+       }
 
        if(level!=CHAINED)
        {
@@ -66,8 +78,8 @@ void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level)
                local_incpath.insert(local_incpath.begin(), bi.local_incpath.begin(), bi.local_incpath.end());
                libmode = bi.libmode;
                rpath_mode = bi.rpath_mode;
-               for(LibModeMap::const_iterator i=bi.libmodes.begin(); i!=bi.libmodes.end(); ++i)
-                       libmodes[i->first] = i->second;
+               for(const auto &kvp: bi.libmodes)
+                       libmodes[kvp.first] = kvp.second;
                keep_symbols.insert(keep_symbols.end(), bi.keep_symbols.begin(), bi.keep_symbols.end());
                debug = bi.debug;
                optimize = bi.optimize;
@@ -86,10 +98,8 @@ void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level)
 
 BuildInfo::LanguageStandard::LanguageStandard(const string &std)
 {
-       string::size_type num = string::npos;
-       for(string::size_type i=0; (num==string::npos && i<std.size()); ++i)
-               if(isdigit(static_cast<unsigned char>(std[i])))
-                       num = i;
+       auto i = find_if(std, [](char c){ return isdigit(static_cast<unsigned char>(c)); });
+       string::size_type num = i-std.begin();
        type = std.substr(0, num);
        year = lexical_cast<unsigned>(std.substr(num));
        year += (year<70 ? 2000 : 1900);