Commit a88afa45 authored by Pavel Vainerman's avatar Pavel Vainerman

Небольшая оптимизация insert ==> emplace

parent b438c2e7
...@@ -1995,7 +1995,7 @@ MBExchange::RTUDevice* MBExchange::addDev( RTUDeviceMap& mp, ModbusRTU::ModbusAd ...@@ -1995,7 +1995,7 @@ MBExchange::RTUDevice* MBExchange::addDev( RTUDeviceMap& mp, ModbusRTU::ModbusAd
return 0; return 0;
} }
mp.insert(RTUDeviceMap::value_type(a, d)); mp.insert( std::make_pair(a, d) );
return d; return d;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
...@@ -2040,7 +2040,7 @@ MBExchange::RegInfo* MBExchange::addReg( RegMap& mp, RegID id, ModbusRTU::Modbus ...@@ -2040,7 +2040,7 @@ MBExchange::RegInfo* MBExchange::addReg( RegMap& mp, RegID id, ModbusRTU::Modbus
ri->mbreg = r; ri->mbreg = r;
ri->id = id; ri->id = id;
mp.insert(RegMap::value_type(id, ri)); mp.insert(std::make_pair(id, ri));
ri->rit = mp.find(id); ri->rit = mp.find(id);
return ri; return ri;
......
...@@ -161,7 +161,7 @@ void RRDServer::initRRD( xmlNode* cnode, int tmID ) ...@@ -161,7 +161,7 @@ void RRDServer::initRRD( xmlNode* cnode, int tmID )
} }
DSInfo ds(dsname, it1.getIntProp("default")); DSInfo ds(dsname, it1.getIntProp("default"));
dsmap.insert( DSMap::value_type(sid, ds) ); dsmap.emplace(sid, ds);
} }
if( dslist.empty() ) if( dslist.empty() )
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <cstdio> #include <cstdio>
#include <string> #include <string>
#include <list> #include <list>
#include <vector>
#include <limits> #include <limits>
#include <ostream> #include <ostream>
#include <unistd.h> #include <unistd.h>
...@@ -171,7 +172,7 @@ namespace UniSetTypes ...@@ -171,7 +172,7 @@ namespace UniSetTypes
/*! Разбивка строки по указанному символу */ /*! Разбивка строки по указанному символу */
IDList explode( const std::string& str, char sep = ',' ); IDList explode( const std::string& str, char sep = ',' );
std::list<std::string> explode_str( const std::string& str, char sep = ',' ); std::vector<std::string> explode_str( const std::string& str, char sep = ',' );
struct ParamSInfo struct ParamSInfo
{ {
......
...@@ -1109,7 +1109,7 @@ void UInterface::CacheOfResolve::cache( const ObjectId id, const ObjectId node, ...@@ -1109,7 +1109,7 @@ void UInterface::CacheOfResolve::cache( const ObjectId id, const ObjectId node,
auto it = mcache.find(k); auto it = mcache.find(k);
if( it == mcache.end() ) if( it == mcache.end() )
mcache.insert(CacheMap::value_type(k, Info(ptr))); mcache.emplace(k, Info(ptr));
else else
{ {
it->second.ptr = ptr; // CORBA::Object::_duplicate(ptr); it->second.ptr = ptr; // CORBA::Object::_duplicate(ptr);
......
...@@ -168,8 +168,8 @@ void ObjectIndex_idXML::read_section( const std::shared_ptr<UniXML>& xml, const ...@@ -168,8 +168,8 @@ void ObjectIndex_idXML::read_section( const std::shared_ptr<UniXML>& xml, const
inf.textName = uni_strdup(textname); inf.textName = uni_strdup(textname);
inf.data = (void*)(xmlNode*)(it); inf.data = (void*)(xmlNode*)(it);
mok.insert(MapObjectKey::value_type(name, inf.id)); // mok[name] = inf.id; mok.emplace(name, inf.id);
omap.insert(MapObjects::value_type(inf.id, std::move(inf))); // omap[inf.id] = inf; omap.emplace(inf.id, std::move(inf));
} }
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
...@@ -220,8 +220,8 @@ void ObjectIndex_idXML::read_nodes( const std::shared_ptr<UniXML>& xml, const st ...@@ -220,8 +220,8 @@ void ObjectIndex_idXML::read_nodes( const std::shared_ptr<UniXML>& xml, const st
inf.textName = uni_strdup(textname); inf.textName = uni_strdup(textname);
inf.data = (void*)(xmlNode*)(it); inf.data = (void*)(xmlNode*)(it);
omap.insert(MapObjects::value_type(inf.id, inf)); // omap[inf.id] = inf; omap.emplace(inf.id, inf);
mok.insert(MapObjectKey::value_type(name, inf.id)); // mok[name] = inf.id; mok.emplace(name, inf.id);
} }
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
......
...@@ -57,7 +57,7 @@ void ProxyManager::attachObject( PassiveObject* po, UniSetTypes::ObjectId id ) ...@@ -57,7 +57,7 @@ void ProxyManager::attachObject( PassiveObject* po, UniSetTypes::ObjectId id )
auto it = omap.find(id); auto it = omap.find(id);
if( it == omap.end() ) if( it == omap.end() )
omap.insert(PObjectMap::value_type(id, po)); omap.emplace(id, po);
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void ProxyManager::detachObject( UniSetTypes::ObjectId id ) void ProxyManager::detachObject( UniSetTypes::ObjectId id )
......
...@@ -216,9 +216,9 @@ UniSetTypes::IDList UniSetTypes::explode( const string& str, char sep ) ...@@ -216,9 +216,9 @@ UniSetTypes::IDList UniSetTypes::explode( const string& str, char sep )
return l; return l;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
std::list<std::string> UniSetTypes::explode_str( const string& str, char sep ) std::vector<std::string> UniSetTypes::explode_str( const string& str, char sep )
{ {
std::list<std::string> l; std::vector<std::string> v;
string::size_type prev = 0; string::size_type prev = 0;
string::size_type pos = 0; string::size_type pos = 0;
...@@ -230,13 +230,13 @@ std::list<std::string> UniSetTypes::explode_str( const string& str, char sep ) ...@@ -230,13 +230,13 @@ std::list<std::string> UniSetTypes::explode_str( const string& str, char sep )
if( !s.empty() ) if( !s.empty() )
{ {
l.emplace_back(s); v.emplace_back(s);
prev = pos + 1; prev = pos + 1;
} }
} }
while( pos != string::npos ); while( pos != string::npos );
return l; return v;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
bool UniSetTypes::is_digit( const std::string& s ) bool UniSetTypes::is_digit( const std::string& s )
......
...@@ -395,7 +395,7 @@ void IOController::ioRegistration( std::shared_ptr<USensorInfo>& ainf, bool forc ...@@ -395,7 +395,7 @@ void IOController::ioRegistration( std::shared_ptr<USensorInfo>& ainf, bool forc
ai->value = ai->default_val; ai->value = ai->default_val;
// более оптимальный способ(при условии вставки первый раз) // более оптимальный способ(при условии вставки первый раз)
ioList.insert( IOStateList::value_type(ainf->si.id, std::move(ai) )); ioList.emplace( IOStateList::value_type(ainf->si.id, std::move(ai) ));
} }
try try
......
...@@ -212,7 +212,7 @@ void IONotifyController::ask( AskMap& askLst, const UniSetTypes::ObjectId sid, ...@@ -212,7 +212,7 @@ void IONotifyController::ask( AskMap& askLst, const UniSetTypes::ObjectId sid,
ConsumerListInfo lst; // создаем новый список ConsumerListInfo lst; // создаем новый список
addConsumer(lst, cons); addConsumer(lst, cons);
// более оптимальный способ(при условии вставки первый раз) // более оптимальный способ(при условии вставки первый раз)
askLst.insert(AskMap::value_type(sid, std::move(lst))); askLst.emplace(sid, std::move(lst));
try try
{ {
...@@ -565,7 +565,7 @@ void IONotifyController::askThreshold(UniSetTypes::ObjectId sid, const UniSetTyp ...@@ -565,7 +565,7 @@ void IONotifyController::askThreshold(UniSetTypes::ObjectId sid, const UniSetTyp
} }
// т.к. делаем move... то надо гарантировать, что дальше уже tli не используется.. // т.к. делаем move... то надо гарантировать, что дальше уже tli не используется..
askTMap.insert(AskThresholdMap::value_type(sid, std::move(tli))); askTMap.emplace(sid, std::move(tli));
} }
else else
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment