Bläddra i källkod

Merge pull request #1504 from guodongxiaren/emplace

replace insert/push_back for pair with emplace/emplace_back
Jiashun Zhu 2 år sedan
förälder
incheckning
ced4c70404

+ 1 - 1
src/brpc/details/naming_service_thread.cpp

@@ -337,7 +337,7 @@ int NamingServiceThread::AddWatcher(NamingServiceWatcher* watcher,
         return -1;
     }
     BAIDU_SCOPED_LOCK(_mutex);
-    if (_watchers.insert(std::make_pair(watcher, filter)).second) {
+    if (_watchers.emplace(watcher, filter).second) {
         if (!_last_sockets.empty()) {
             std::vector<ServerId> added_ids;
             ServerNodeWithId2ServerId(_last_sockets, &added_ids, filter);

+ 1 - 1
src/brpc/protocol.cpp

@@ -116,7 +116,7 @@ void ListProtocols(std::vector<std::pair<ProtocolType, Protocol> >* vec) {
     ProtocolEntry* const protocol_map = get_protocol_map();
     for (size_t i = 0; i < MAX_PROTOCOL_SIZE; ++i) {
         if (protocol_map[i].valid.load(butil::memory_order_acquire)) {
-            vec->push_back(std::make_pair((ProtocolType)i, protocol_map[i].protocol));
+            vec->emplace_back((ProtocolType)i, protocol_map[i].protocol);
         }
     }
 }

+ 1 - 1
src/butil/debug/crash_logging.cc

@@ -151,7 +151,7 @@ size_t InitCrashKeys(const CrashKey* const keys, size_t count,
 
   size_t total_keys = 0;
   for (size_t i = 0; i < count; ++i) {
-    g_crash_keys_->insert(std::make_pair(keys[i].key_name, keys[i]));
+    g_crash_keys_->emplace(keys[i].key_name, keys[i]);
     total_keys += NumChunksForLength(keys[i].max_length);
     DCHECK_LT(keys[i].max_length, kLargestValueAllowed);
   }

+ 1 - 1
src/butil/debug/stack_trace_posix.cc

@@ -644,7 +644,7 @@ class SandboxSymbolizeHelper {
         if (modules_.find(region.path) == modules_.end()) {
           int fd = open(region.path.c_str(), O_RDONLY | O_CLOEXEC);
           if (fd >= 0) {
-            modules_.insert(std::make_pair(region.path, fd));
+            modules_.emplace(region.path, fd);
           } else {
             LOG(WARNING) << "Failed to open file: " << region.path
                          << "\n  Error: " << strerror(errno);

+ 1 - 1
src/butil/logging.cc

@@ -1291,7 +1291,7 @@ struct VModuleList {
             if (name.find_first_of("*?") == std::string::npos) {
                 _exact_names[name] = verbose_level;
             } else {
-                _wild_names.push_back(std::make_pair(name, verbose_level));
+                _wild_names.emplace_back(name, verbose_level);
             }
         }
         // Reverse _wild_names so that latter wild cards override former ones.

+ 1 - 1
src/butil/posix/global_descriptors.cc

@@ -46,7 +46,7 @@ void GlobalDescriptors::Set(Key key, int fd) {
     }
   }
 
-  descriptors_.push_back(std::make_pair(key, fd));
+  descriptors_.emplace_back(key, fd);
 }
 
 void GlobalDescriptors::Reset(const Mapping& mapping) {

+ 1 - 1
src/butil/strings/string_split.cc

@@ -185,7 +185,7 @@ bool SplitStringIntoKeyValuePairsT(const STR& line,
       // value or key; just record that the split failed.
       success = false;
     }
-    key_value_pairs->push_back(std::make_pair(key, value));
+    key_value_pairs->emplace_back(key, value);
   }
   return success;
 }

+ 1 - 1
src/butil/synchronization/waitable_event_posix.cc

@@ -235,7 +235,7 @@ size_t WaitableEvent::WaitMany(WaitableEvent** raw_waitables,
   std::vector<std::pair<WaitableEvent*, size_t> > waitables;
   waitables.reserve(count);
   for (size_t i = 0; i < count; ++i)
-    waitables.push_back(std::make_pair(raw_waitables[i], i));
+    waitables.emplace_back(raw_waitables[i], i);
 
   DCHECK_EQ(count, waitables.size());
 

+ 1 - 1
src/butil/thread_local.cpp

@@ -47,7 +47,7 @@ public:
             if (_fns.capacity() < 16) {
                 _fns.reserve(16);
             }
-            _fns.push_back(std::make_pair(fn, arg));
+            _fns.emplace_back(fn, arg);
         } catch (...) {
             errno = ENOMEM;
             return -1;

+ 3 - 3
src/bvar/variable.cpp

@@ -635,11 +635,11 @@ public:
             FileDumper *f = new FileDumper(
                     path.AddExtension(key).AddExtension("data").value(), s);
             WildcardMatcher *m = new WildcardMatcher(value, '?', true);
-            dumpers.push_back(std::make_pair(f, m));
+            dumpers.emplace_back(f, m);
         }
-        dumpers.push_back(std::make_pair(
+        dumpers.emplace_back(
                     new FileDumper(path.AddExtension("data").value(), s), 
-                    (WildcardMatcher *)NULL));
+                    (WildcardMatcher *)NULL);
     }
     ~FileDumperGroup() {
         for (size_t i = 0; i < dumpers.size(); ++i) {