Skip to content

Commit

Permalink
Needless temporary gone
Browse files Browse the repository at this point in the history
Summary: We might be doing:
1) Create a temporary
2) Copy/Move out of it
3) Destroy that temporary.
Which isn't needed in many places.
And copy/move elision doesn't work for a temporary
bound to a reference.

We can forward arguments, directly.
To get the work done three constructors were added.

Closes #222

Reviewed By: @JoelMarcey, @yfeldblum

Differential Revision: D2151731

Pulled By: @sgolemon
  • Loading branch information
cppfool authored and sgolemon committed Jun 12, 2015
1 parent 143b92e commit af7afa4
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion folly/Subprocess.cpp
Expand Up @@ -819,7 +819,7 @@ void Subprocess::closeParentFd(int childFd) {
std::vector<Subprocess::ChildPipe> Subprocess::takeOwnershipOfPipes() {
std::vector<Subprocess::ChildPipe> pipes;
for (auto& p : pipes_) {
pipes.emplace_back(ChildPipe{p.childFd, std::move(p.pipe)});
pipes.emplace_back(p.childFd, std::move(p.pipe));
}
pipes_.clear();
return pipes;
Expand Down
1 change: 1 addition & 0 deletions folly/Subprocess.h
Expand Up @@ -714,6 +714,7 @@ class Subprocess {
* No, you may NOT call this from a communicate() callback.
*/
struct ChildPipe {
ChildPipe(int fd, folly::File&& ppe) : childFd(fd), pipe(std::move(ppe)) {}
int childFd;
folly::File pipe; // Owns the parent FD
};
Expand Down
9 changes: 4 additions & 5 deletions folly/experimental/JSONSchema.cpp
Expand Up @@ -381,8 +381,8 @@ struct PropertiesValidator final : IValidator {
for (const auto& pair : patternProperties->items()) {
if (pair.first.isString()) {
patternPropertyValidators_.emplace_back(
make_pair(boost::regex(pair.first.getString().toStdString()),
SchemaValidator::make(context, pair.second)));
boost::regex(pair.first.getString().toStdString()),
SchemaValidator::make(context, pair.second));
}
}
}
Expand Down Expand Up @@ -466,9 +466,8 @@ struct DependencyValidator final : IValidator {
propertyDep_.emplace_back(std::move(p));
}
if (pair.second.isObject()) {
schemaDep_.emplace_back(
make_pair(pair.first.getString(),
SchemaValidator::make(context, pair.second)));
schemaDep_.emplace_back(pair.first.getString(),
SchemaValidator::make(context, pair.second));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion folly/experimental/fibers/SimpleLoopController.h
Expand Up @@ -77,7 +77,7 @@ class SimpleLoopController : public LoopController {
}

void timedSchedule(std::function<void()> func, TimePoint time) override {
scheduledFuncs_.push_back({time, std::move(func)});
scheduledFuncs_.emplace_back(time, std::move(func));
}

private:
Expand Down
2 changes: 1 addition & 1 deletion folly/experimental/fibers/test/FibersTest.cpp
Expand Up @@ -581,7 +581,7 @@ TEST(FiberManager, forEach) {
std::vector<std::pair<size_t, int>> results;
forEach(funcs.begin(), funcs.end(),
[&results](size_t id, int result) {
results.push_back(std::make_pair(id, result));
results.emplace_back(id, result);
});
EXPECT_EQ(3, results.size());
EXPECT_TRUE(pendingFibers.empty());
Expand Down
2 changes: 1 addition & 1 deletion folly/experimental/test/EventCountTest.cpp
Expand Up @@ -68,7 +68,7 @@ void randomPartition(Random& random, T key, int n,
int m = std::min(n, 1000);
std::uniform_int_distribution<uint32_t> u(1, m);
int cut = u(random);
out.push_back(std::make_pair(key, cut));
out.emplace_back(key, cut);
n -= cut;
}
}
Expand Down
2 changes: 1 addition & 1 deletion folly/futures/Future-inl.h
Expand Up @@ -704,7 +704,7 @@ collectN(InputIterator first, InputIterator last, size_t n) {
auto c = ++ctx->completed;
if (c <= n) {
assert(ctx->v.size() < n);
ctx->v.push_back(std::make_pair(i, std::move(t)));
ctx->v.emplace_back(i, std::move(t));
if (c == n) {
ctx->p.setTry(Try<V>(std::move(ctx->v)));
}
Expand Down
2 changes: 2 additions & 0 deletions folly/io/async/SSLContext.h
Expand Up @@ -81,6 +81,8 @@ class SSLContext {
};

struct NextProtocolsItem {
NextProtocolsItem(int wt, const std::list<std::string>& ptcls):
weight(wt), protocols(ptcls) {}
int weight;
std::list<std::string> protocols;
};
Expand Down
2 changes: 1 addition & 1 deletion folly/io/async/test/EventBaseTest.cpp
Expand Up @@ -1106,7 +1106,7 @@ struct RunInThreadArg {
};

void runInThreadTestFunc(RunInThreadArg* arg) {
arg->data->values.push_back(make_pair(arg->thread, arg->value));
arg->data->values.emplace_back(arg->thread, arg->value);
RunInThreadData* data = arg->data;
delete arg;

Expand Down
2 changes: 1 addition & 1 deletion folly/test/DeterministicSchedule.cpp
Expand Up @@ -247,7 +247,7 @@ Futex<DeterministicAtomic>::futexWaitImpl(
futexLock.lock();
if (data == expected) {
auto& queue = futexQueues[this];
queue.push_back(std::make_pair(waitMask, &awoken));
queue.emplace_back(waitMask, &awoken);
auto ours = queue.end();
ours--;
while (!awoken) {
Expand Down
10 changes: 4 additions & 6 deletions folly/test/DynamicTest.cpp
Expand Up @@ -52,17 +52,15 @@ TEST(Dynamic, ObjectBasics) {
EXPECT_EQ(*newObject.keys().begin(), newObject.items().begin()->first);
EXPECT_EQ(*newObject.values().begin(), newObject.items().begin()->second);
std::vector<std::pair<folly::fbstring, dynamic>> found;
found.push_back(std::make_pair(
newObject.keys().begin()->asString(),
*newObject.values().begin()));
found.emplace_back(newObject.keys().begin()->asString(),
*newObject.values().begin());

EXPECT_EQ(*boost::next(newObject.keys().begin()),
boost::next(newObject.items().begin())->first);
EXPECT_EQ(*boost::next(newObject.values().begin()),
boost::next(newObject.items().begin())->second);
found.push_back(std::make_pair(
boost::next(newObject.keys().begin())->asString(),
*boost::next(newObject.values().begin())));
found.emplace_back(boost::next(newObject.keys().begin())->asString(),
*boost::next(newObject.values().begin()));

std::sort(found.begin(), found.end());

Expand Down
8 changes: 6 additions & 2 deletions folly/wangle/ssl/SSLContextConfig.h
Expand Up @@ -31,6 +31,10 @@ struct SSLContextConfig {
~SSLContextConfig() {}

struct CertificateInfo {
CertificateInfo(const std::string& crtPath,
const std::string& kyPath,
const std::string& passwdPath)
: certPath(crtPath), keyPath(kyPath), passwordPath(passwdPath) {}
std::string certPath;
std::string keyPath;
std::string passwordPath;
Expand All @@ -49,7 +53,7 @@ struct SSLContextConfig {
void addCertificate(const std::string& certPath,
const std::string& keyPath,
const std::string& passwordPath) {
certificates.emplace_back(CertificateInfo{certPath, keyPath, passwordPath});
certificates.emplace_back(certPath, keyPath, passwordPath);
}

/**
Expand All @@ -58,7 +62,7 @@ struct SSLContextConfig {
*/
void setNextProtocols(const std::list<std::string>& inNextProtocols) {
nextProtocols.clear();
nextProtocols.push_back({1, inNextProtocols});
nextProtocols.emplace_back(1, inNextProtocols);
}

typedef std::function<bool(char const* server_name)> SNINoMatchFn;
Expand Down
3 changes: 1 addition & 2 deletions folly/wangle/ssl/SSLSessionCacheManager.cpp
Expand Up @@ -251,8 +251,7 @@ SSL_SESSION* SSLSessionCacheManager::getSession(SSL* ssl,
SSLUtil::hexlify(sessionId);
std::unique_ptr<DelayedDestruction::DestructorGuard> dg(
new DelayedDestruction::DestructorGuard(sslSocket));
pit->second.waiters.push_back(
std::make_pair(sslSocket, std::move(dg)));
pit->second.waiters.emplace_back(sslSocket, std::move(dg));
*copyflag = SSL_SESSION_CB_WOULD_BLOCK;
return nullptr;
}
Expand Down

0 comments on commit af7afa4

Please sign in to comment.