-#include <algorithm>
#include <set>
+#include <msp/core/algorithm.h>
#include <msp/strings/format.h>
#include "buildinfo.h"
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++);
}
}
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;
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)
+ for(const auto &kvp: bi.standards)
{
- StandardMap::iterator j = standards.find(i->first);
+ auto j = standards.find(kvp.first);
if(j==standards.end())
- standards.insert(*i);
- else if(i->second.type!=j->second.type || i->second.year!=j->second.year)
+ standards.insert(kvp);
+ else if(kvp.second.type!=j->second.type || kvp.second.year!=j->second.year)
{
- if(!i->second.type.compare(0, 3, "gnu"))
- j->second.type = i->second.type;
- if(i->second.year>j->second.year)
- j->second.year = i->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;
}
}
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;
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);