Merge pull request #4800 from sfc-gh-tclinkenbeard/remove-extra-copies

Remove unnecessary temporary objects while growing objects of type std::vector<std::pair<A, B>>
This commit is contained in:
Jingyu Zhou 2021-06-07 13:23:50 -07:00 committed by GitHub
commit e34df983ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 52 additions and 52 deletions

View File

@ -219,7 +219,7 @@ GetRangeResult get_range(fdb::Transaction& tr,
for (int i = 0; i < out_count; ++i) {
std::string key((const char*)out_kv[i].key, out_kv[i].key_length);
std::string value((const char*)out_kv[i].value, out_kv[i].value_length);
results.push_back(std::make_pair(key, value));
results.emplace_back(key, value);
}
return GetRangeResult{ results, out_more != 0, 0 };
}

View File

@ -3357,7 +3357,7 @@ int main(int argc, char* argv[]) {
deleteData = true;
break;
case OPT_MIN_CLEANUP_SECONDS:
knobs.push_back(std::make_pair("min_cleanup_seconds", args->OptionArg()));
knobs.emplace_back("min_cleanup_seconds", args->OptionArg());
break;
case OPT_FORCE:
forceAction = true;
@ -3452,7 +3452,7 @@ int main(int argc, char* argv[]) {
return FDB_EXIT_ERROR;
}
syn = syn.substr(7);
knobs.push_back(std::make_pair(syn, args->OptionArg()));
knobs.emplace_back(syn, args->OptionArg());
break;
}
case OPT_BACKUPKEYS:
@ -4212,7 +4212,7 @@ int main(int argc, char* argv[]) {
s = s.substr(LiteralStringRef("struct ").size());
#endif
typeNames.push_back(std::make_pair(s, i->first));
typeNames.emplace_back(s, i->first);
}
std::sort(typeNames.begin(), typeNames.end());
for (int i = 0; i < typeNames.size(); i++) {

View File

@ -3108,7 +3108,7 @@ struct CLIOptions {
return FDB_EXIT_ERROR;
}
syn = syn.substr(7);
knobs.push_back(std::make_pair(syn, args.OptionArg()));
knobs.emplace_back(syn, args.OptionArg());
break;
}
case OPT_DEBUG_TLS:

View File

@ -95,7 +95,7 @@ public:
if (itr != optionsIndexMap.end()) {
options.erase(itr->second);
}
options.push_back(std::make_pair(option, value));
options.emplace_back(option, value);
optionsIndexMap[option] = --options.end();
}
@ -107,4 +107,4 @@ public:
type::optionInfo.insert( \
var, FDBOptionInfo(name, comment, parameterComment, hasParameter, hidden, persistent, defaultFor));
#endif
#endif

View File

@ -785,7 +785,7 @@ ConfigureAutoResult parseConfig(StatusObject const& status) {
}
if (processClass.classType() != ProcessClass::TesterClass) {
machine_processes[machineId].push_back(std::make_pair(addr, processClass));
machine_processes[machineId].emplace_back(addr, processClass);
processCount++;
}
}

View File

@ -434,9 +434,9 @@ Optional<std::pair<LeaderInfo, bool>> getLeader(const vector<Optional<LeaderInfo
maskedNominees.reserve(nominees.size());
for (int i = 0; i < nominees.size(); i++) {
if (nominees[i].present()) {
maskedNominees.push_back(std::make_pair(
maskedNominees.emplace_back(
UID(nominees[i].get().changeID.first() & LeaderInfo::changeIDMask, nominees[i].get().changeID.second()),
i));
i);
}
}
@ -586,7 +586,7 @@ OpenDatabaseRequest ClientData::getRequest() {
auto& entry = issueMap[it];
entry.count++;
if (entry.examples.size() < CLIENT_KNOBS->CLIENT_EXAMPLE_AMOUNT) {
entry.examples.push_back(std::make_pair(ci.first, ci.second.traceLogGroup));
entry.examples.emplace_back(ci.first, ci.second.traceLogGroup);
}
}
if (ci.second.versions.size()) {
@ -597,19 +597,19 @@ OpenDatabaseRequest ClientData::getRequest() {
auto& entry = versionMap[it];
entry.count++;
if (entry.examples.size() < CLIENT_KNOBS->CLIENT_EXAMPLE_AMOUNT) {
entry.examples.push_back(std::make_pair(ci.first, ci.second.traceLogGroup));
entry.examples.emplace_back(ci.first, ci.second.traceLogGroup);
}
}
auto& maxEntry = maxProtocolMap[maxProtocol];
maxEntry.count++;
if (maxEntry.examples.size() < CLIENT_KNOBS->CLIENT_EXAMPLE_AMOUNT) {
maxEntry.examples.push_back(std::make_pair(ci.first, ci.second.traceLogGroup));
maxEntry.examples.emplace_back(ci.first, ci.second.traceLogGroup);
}
} else {
auto& entry = versionMap[ClientVersionRef()];
entry.count++;
if (entry.examples.size() < CLIENT_KNOBS->CLIENT_EXAMPLE_AMOUNT) {
entry.examples.push_back(std::make_pair(ci.first, ci.second.traceLogGroup));
entry.examples.emplace_back(ci.first, ci.second.traceLogGroup);
}
}
}

View File

@ -595,7 +595,7 @@ Reference<IDatabase> DLApi::createDatabase(const char* clusterFilePath) {
void DLApi::addNetworkThreadCompletionHook(void (*hook)(void*), void* hookParameter) {
MutexHolder holder(lock);
threadCompletionHooks.push_back(std::make_pair(hook, hookParameter));
threadCompletionHooks.emplace_back(hook, hookParameter);
}
// MultiVersionTransaction
@ -947,7 +947,7 @@ void MultiVersionDatabase::setOption(FDBDatabaseOptions::Option option, Optional
value.castTo<Standalone<StringRef>>());
}
dbState->options.push_back(std::make_pair(option, value.castTo<Standalone<StringRef>>()));
dbState->options.emplace_back(option, value.castTo<Standalone<StringRef>>());
if (dbState->db) {
dbState->db->setOption(option, value);
@ -1559,7 +1559,7 @@ void MultiVersionApi::setNetworkOptionInternal(FDBNetworkOptions::Option option,
runOnExternalClientsAllThreads(
[option, value](Reference<ClientInfo> client) { client->api->setNetworkOption(option, value); });
} else {
options.push_back(std::make_pair(option, value.castTo<Standalone<StringRef>>()));
options.emplace_back(option, value.castTo<Standalone<StringRef>>());
}
}
}

View File

@ -474,7 +474,7 @@ void ThreadSafeApi::addNetworkThreadCompletionHook(void (*hook)(void*), void* ho
MutexHolder holder(lock); // We could use the network thread to protect this action, but then we can't guarantee
// upon return that the hook is set.
threadCompletionHooks.push_back(std::make_pair(hook, hookParameter));
threadCompletionHooks.emplace_back(hook, hookParameter);
}
IClientApi* ThreadSafeApi::api = new ThreadSafeApi();

View File

@ -856,7 +856,7 @@ void load_conf(const char* confpath, uid_t& uid, gid_t& gid, sigset_t* mask, fdb
if (id_command[i.first]->kill_on_configuration_change) {
kill_ids.push_back(i.first);
start_ids.push_back(std::make_pair(i.first, cmd));
start_ids.emplace_back(i.first, cmd);
}
} else {
log_msg(SevInfo, "Updated configuration for %s\n", id_command[i.first]->ssection.c_str());

View File

@ -24,7 +24,7 @@
void HealthMonitor::reportPeerClosed(const NetworkAddress& peerAddress) {
purgeOutdatedHistory();
peerClosedHistory.push_back(std::make_pair(now(), peerAddress));
peerClosedHistory.emplace_back(now(), peerAddress);
peerClosedNum[peerAddress] += 1;
}

View File

@ -599,8 +599,8 @@ public:
std::vector<std::tuple<ProcessClass::Fitness, int, bool, int, Field>> orderedFields;
for (auto& it : fieldsWithMin) {
auto& fitness = field_fitness[it];
orderedFields.push_back(std::make_tuple(
std::get<0>(fitness), std::get<1>(fitness), std::get<2>(fitness), field_count[it], it));
orderedFields.emplace_back(
std::get<0>(fitness), std::get<1>(fitness), std::get<2>(fitness), field_count[it], it);
}
std::sort(orderedFields.begin(), orderedFields.end());
int totalFields = desired / minPerField;

View File

@ -1461,7 +1461,7 @@ ACTOR static Future<Void> doKeyServerLocationRequest(GetKeyServerLocationsReques
ssis.push_back(it->interf);
maybeAddTssMapping(rep, commitData, tssMappingsIncluded, it->interf.id());
}
rep.results.push_back(std::make_pair(r.range(), ssis));
rep.results.emplace_back(r.range(), ssis);
} else if (!req.reverse) {
int count = 0;
for (auto r = commitData->keyInfo.rangeContaining(req.begin);
@ -1473,7 +1473,7 @@ ACTOR static Future<Void> doKeyServerLocationRequest(GetKeyServerLocationsReques
ssis.push_back(it->interf);
maybeAddTssMapping(rep, commitData, tssMappingsIncluded, it->interf.id());
}
rep.results.push_back(std::make_pair(r.range(), ssis));
rep.results.emplace_back(r.range(), ssis);
count++;
}
} else {
@ -1486,7 +1486,7 @@ ACTOR static Future<Void> doKeyServerLocationRequest(GetKeyServerLocationsReques
ssis.push_back(it->interf);
maybeAddTssMapping(rep, commitData, tssMappingsIncluded, it->interf.id());
}
rep.results.push_back(std::make_pair(r.range(), ssis));
rep.results.emplace_back(r.range(), ssis);
if (r == commitData->keyInfo.ranges().begin()) {
break;
}

View File

@ -460,10 +460,10 @@ ACTOR Future<Reference<InitialDataDistribution>> getInitialDataDistribution(Data
for (int i = 0; i < serverList.get().size(); i++) {
auto ssi = decodeServerListValue(serverList.get()[i].value);
if (!ssi.isTss()) {
result->allServers.push_back(std::make_pair(ssi, id_data[ssi.locality.processId()].processClass));
result->allServers.emplace_back(ssi, id_data[ssi.locality.processId()].processClass);
server_dc[ssi.id()] = ssi.locality.dcId();
} else {
tss_servers.push_back(std::make_pair(ssi, id_data[ssi.locality.processId()].processClass));
tss_servers.emplace_back(ssi, id_data[ssi.locality.processId()].processClass);
}
}
@ -3874,7 +3874,7 @@ ACTOR Future<vector<std::pair<StorageServerInterface, ProcessClass>>> getServerL
vector<std::pair<StorageServerInterface, ProcessClass>> results;
for (int i = 0; i < serverList.get().size(); i++) {
auto ssi = decodeServerListValue(serverList.get()[i].value);
results.push_back(std::make_pair(ssi, id_data[ssi.locality.processId()].processClass));
results.emplace_back(ssi, id_data[ssi.locality.processId()].processClass);
}
return results;

View File

@ -1032,7 +1032,7 @@ ACTOR Future<Void> dataDistributionRelocator(DDQueueData* self, RelocateData rd,
anyWithSource = true;
}
bestTeams.push_back(std::make_pair(bestTeam.first.get(), bestTeam.second));
bestTeams.emplace_back(bestTeam.first.get(), bestTeam.second);
tciIndex++;
}
if (foundTeams && anyHealthy) {

View File

@ -401,7 +401,7 @@ private:
if (o->op == OpSet) {
if (sequential) {
KeyValueMapPair pair(o->p1, o->p2);
dataSets.push_back(std::make_pair(pair, pair.arena.getSize() + data.getElementBytes()));
dataSets.emplace_back(pair, pair.arena.getSize() + data.getElementBytes());
} else {
data.insert(o->p1, o->p2);
}

View File

@ -838,7 +838,7 @@ void commitMessages(Reference<LogData> self,
TEST(true); // Splitting commit messages across multiple blocks
messages1 = StringRef(block.end(), bytes);
block.append(block.arena(), messages.begin(), bytes);
self->messageBlocks.push_back(std::make_pair(version, block));
self->messageBlocks.emplace_back(version, block);
addedBytes += int64_t(block.size()) * SERVER_KNOBS->TLOG_MESSAGE_BLOCK_OVERHEAD_FACTOR;
messages = messages.substr(bytes);
}
@ -851,7 +851,7 @@ void commitMessages(Reference<LogData> self,
// Copy messages into block
ASSERT(messages.size() <= block.capacity() - block.size());
block.append(block.arena(), messages.begin(), messages.size());
self->messageBlocks.push_back(std::make_pair(version, block));
self->messageBlocks.emplace_back(version, block);
addedBytes += int64_t(block.size()) * SERVER_KNOBS->TLOG_MESSAGE_BLOCK_OVERHEAD_FACTOR;
messages = StringRef(block.end() - messages.size(), messages.size());
@ -869,7 +869,7 @@ void commitMessages(Reference<LogData> self,
int offs = tag->messageOffsets[m];
uint8_t const* p =
offs < messages1.size() ? messages1.begin() + offs : messages.begin() + offs - messages1.size();
tsm->value.version_messages.push_back(std::make_pair(version, LengthPrefixedStringRef((uint32_t*)p)));
tsm->value.version_messages.emplace_back(version, LengthPrefixedStringRef((uint32_t*)p));
if (tsm->value.version_messages.back().second.expectedSize() > SERVER_KNOBS->MAX_MESSAGE_SIZE) {
TraceEvent(SevWarnAlways, "LargeMessage")
.detail("Size", tsm->value.version_messages.back().second.expectedSize());

View File

@ -233,7 +233,7 @@ ACTOR Future<Void> resolveBatch(Reference<Resolver> self, ResolveTransactionBatc
self->resolvedStateBytes += stateBytes;
if (stateBytes > 0)
self->recentStateTransactionSizes.push_back(std::make_pair(req.version, stateBytes));
self->recentStateTransactionSizes.emplace_back(req.version, stateBytes);
ASSERT(req.version >= firstUnseenVersion);
ASSERT(firstUnseenVersion >= self->debugMinRecentStateVersion);

View File

@ -189,7 +189,7 @@ ACTOR Future<Void> monitorWorkerLiveness(Reference<RestoreWorkerData> self) {
loop {
std::vector<std::pair<UID, RestoreSimpleRequest>> requests;
for (auto& worker : self->workerInterfaces) {
requests.push_back(std::make_pair(worker.first, RestoreSimpleRequest()));
requests.emplace_back(worker.first, RestoreSimpleRequest());
}
wait(sendBatchRequests(&RestoreWorkerInterface::heartbeat, self->workerInterfaces, requests));
wait(delay(60.0));

View File

@ -1807,7 +1807,7 @@ static Future<vector<std::pair<iface, EventMap>>> getServerMetrics(
++futureItr;
}
results.push_back(std::make_pair(servers[i], serverResults));
results.emplace_back(servers[i], serverResults);
}
return results;

View File

@ -112,7 +112,7 @@ struct TransientStorageMetricSample : StorageMetricSample {
int64_t addAndExpire(KeyRef key, int64_t metric, double expiration) {
int64_t x = add(key, metric);
if (x)
queue.push_back(std::make_pair(expiration, std::make_pair(*sample.find(key), -x)));
queue.emplace_back(expiration, std::make_pair(*sample.find(key), -x));
return x;
}

View File

@ -2118,7 +2118,7 @@ struct TagPartitionedLogSystem : ILogSystem, ReferenceCounted<TagPartitionedLogS
std::vector<Reference<AsyncVar<bool>>> failed;
for (const auto& logVar : logServers.back()->logServers) {
allLogServers.push_back(std::make_pair(logVar, coreSet.tLogPolicy));
allLogServers.emplace_back(logVar, coreSet.tLogPolicy);
failed.push_back(makeReference<AsyncVar<bool>>());
failureTrackers.push_back(monitorLog(logVar, failed.back()));
}
@ -2130,7 +2130,7 @@ struct TagPartitionedLogSystem : ILogSystem, ReferenceCounted<TagPartitionedLogS
for (const auto& logSet : oldLogData.back().tLogs) {
for (const auto& logVar : logSet->logServers) {
allLogServers.push_back(std::make_pair(logVar, logSet->tLogPolicy));
allLogServers.emplace_back(logVar, logSet->tLogPolicy);
}
}
}

View File

@ -1050,7 +1050,7 @@ private:
flushAndExit(FDB_EXIT_ERROR);
}
syn = syn.substr(7);
knobs.push_back(std::make_pair(syn, args.OptionArg()));
knobs.emplace_back(syn, args.OptionArg());
break;
}
case OPT_UNITTESTPARAM: {
@ -1359,10 +1359,10 @@ private:
}
// SOMEDAY: ideally we'd have some better way to express that a knob should be elevated to formal
// parameter
knobs.push_back(std::make_pair(
knobs.emplace_back(
"page_cache_4k",
format("%ld", ti.get() / 4096 * 4096))); // The cache holds 4K pages, so we can truncate this to the
// next smaller multiple of 4K.
format("%ld", ti.get() / 4096 * 4096)); // The cache holds 4K pages, so we can truncate this to the
// next smaller multiple of 4K.
break;
case OPT_BUGGIFY:
if (!strcmp(args.OptionArg(), "on"))
@ -2143,7 +2143,7 @@ int main(int argc, char* argv[]) {
s = s.substr(LiteralStringRef("struct ").size());
#endif
typeNames.push_back(std::make_pair(s, i->first));
typeNames.emplace_back(s, i->first);
}
std::sort(typeNames.begin(), typeNames.end());
for (int i = 0; i < typeNames.size(); i++) {

View File

@ -556,7 +556,7 @@ private:
LogEvent(EVENTLOG_INFORMATION_TYPE,
format("Found new configuration for process (ID %d)", sp->id));
stop_processes.push_back(sp);
start_ids.push_back(std::make_pair(sp->id, cmd));
start_ids.emplace_back(sp->id, cmd);
} else if (cmd.quiet != sp->command.quiet || cmd.restartDelay != sp->command.restartDelay) {
// Update restartDelay and quiet but do not restart running processes
if (!cmd.quiet || !sp->command.quiet)
@ -585,7 +585,7 @@ private:
std::string section(it->pItem, dot - it->pItem);
Command cmd = makeCommand(ini, section, id);
if (cmd.valid) {
start_ids.push_back(std::make_pair(id, cmd));
start_ids.emplace_back(id, cmd);
} else {
LogEvent(
EVENTLOG_ERROR_TYPE,

View File

@ -564,7 +564,7 @@ void FastAllocator<Size>::releaseThreadMagazines() {
if (thr.freelist || thr.alternate) {
if (thr.freelist) {
ASSERT(thr.count > 0 && thr.count <= magazine_size);
globalData()->partial_magazines.push_back(std::make_pair(thr.count, thr.freelist));
globalData()->partial_magazines.emplace_back(thr.count, thr.freelist);
globalData()->partialMagazineUnallocatedMemory += thr.count * Size;
}
if (thr.alternate) {

View File

@ -2998,7 +2998,7 @@ void outOfMemory() {
else if (StringRef(s).startsWith(LiteralStringRef("struct ")))
s = s.substr(LiteralStringRef("struct ").size());
#endif
typeNames.push_back(std::make_pair(s, i->first));
typeNames.emplace_back(s, i->first);
}
std::sort(typeNames.begin(), typeNames.end());
for (int i = 0; i < typeNames.size(); i++) {

View File

@ -285,7 +285,7 @@ SystemStatistics customSystemMonitor(std::string eventName, StatisticsState* sta
else if (StringRef(s).startsWith(LiteralStringRef("struct ")))
s = s.substr(LiteralStringRef("struct ").size());
#endif
typeNames.push_back(std::make_pair(s, i->first));
typeNames.emplace_back(s, i->first);
}
std::sort(typeNames.begin(), typeNames.end());
for (int i = 0; i < typeNames.size(); i++) {

View File

@ -881,7 +881,7 @@ struct EventMetric final : E, ReferenceCounted<EventMetric<E>>, MetricUtil<Event
time.flushField(mk, rollTime, batch);
flushFields(typename Descriptor<E>::field_indexes(), mk, rollTime, batch);
if (!latestRecorded) {
batch.updates.push_back(std::make_pair(mk.packLatestKey(), StringRef()));
batch.updates.emplace_back(mk.packLatestKey(), StringRef());
latestRecorded = true;
}
}
@ -1249,7 +1249,7 @@ public:
void flushData(const MetricKeyRef& mk, uint64_t rollTime, MetricUpdateBatch& batch) override {
if (!recorded) {
batch.updates.push_back(std::make_pair(mk.packLatestKey(), getLatestAsValue()));
batch.updates.emplace_back(mk.packLatestKey(), getLatestAsValue());
recorded = true;
}

View File

@ -198,7 +198,7 @@ void DynamicEventMetric::flushData(MetricKeyRef const& mk, uint64_t rollTime, Me
for (auto& [name, field] : fields)
field->flushField(mk, rollTime, batch);
if (!latestRecorded) {
batch.updates.push_back(std::make_pair(mk.packLatestKey(), StringRef()));
batch.updates.emplace_back(mk.packLatestKey(), StringRef());
latestRecorded = true;
}
}