Commit 2d41ab6d authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Let RequestContext::setContext take by reference

Summary: [Folly] Let `RequestContext::setContext` and `RequestContextScopeGuard` members take `shared_ptr<RequestContex>` by reference. Saves a small amount on code size and runtime performance due to code size.

Reviewed By: spalamarchuk

Differential Revision: D15074704

fbshipit-source-id: 20f1149b8c56d6c4375d63fe21560bdda5e5ccae
parent 16c1cb3b
...@@ -229,7 +229,14 @@ void exec_set_difference(const TData& data, const TData& other, TExec&& exec) { ...@@ -229,7 +229,14 @@ void exec_set_difference(const TData& data, const TData& other, TExec&& exec) {
} // namespace } // namespace
std::shared_ptr<RequestContext> RequestContext::setContext( std::shared_ptr<RequestContext> RequestContext::setContext(
std::shared_ptr<RequestContext> newCtx) { std::shared_ptr<RequestContext> const& newCtx) {
return setContext(copy(newCtx));
}
std::shared_ptr<RequestContext> RequestContext::setContext(
std::shared_ptr<RequestContext>&& newCtx_) {
auto newCtx = std::move(newCtx_); // enforce that it is really moved-from
auto& staticCtx = getStaticContext(); auto& staticCtx = getStaticContext();
if (newCtx == staticCtx) { if (newCtx == staticCtx) {
return newCtx; return newCtx;
......
...@@ -191,7 +191,9 @@ class RequestContext { ...@@ -191,7 +191,9 @@ class RequestContext {
// A shared_ptr is used, because many request may fan out across // A shared_ptr is used, because many request may fan out across
// multiple threads, or do post-send processing, etc. // multiple threads, or do post-send processing, etc.
static std::shared_ptr<RequestContext> setContext( static std::shared_ptr<RequestContext> setContext(
std::shared_ptr<RequestContext> ctx); std::shared_ptr<RequestContext> const& ctx);
static std::shared_ptr<RequestContext> setContext(
std::shared_ptr<RequestContext>&& ctx);
static std::shared_ptr<RequestContext> saveContext() { static std::shared_ptr<RequestContext> saveContext() {
return getStaticContext(); return getStaticContext();
...@@ -271,7 +273,9 @@ class RequestContextScopeGuard { ...@@ -271,7 +273,9 @@ class RequestContextScopeGuard {
// Set a RequestContext that was previously captured by saveContext(). It will // Set a RequestContext that was previously captured by saveContext(). It will
// be automatically reset to the original value when this goes out of scope. // be automatically reset to the original value when this goes out of scope.
explicit RequestContextScopeGuard(std::shared_ptr<RequestContext> ctx) explicit RequestContextScopeGuard(std::shared_ptr<RequestContext> const& ctx)
: prev_(RequestContext::setContext(ctx)) {}
explicit RequestContextScopeGuard(std::shared_ptr<RequestContext>&& ctx)
: prev_(RequestContext::setContext(std::move(ctx))) {} : prev_(RequestContext::setContext(std::move(ctx))) {}
~RequestContextScopeGuard() { ~RequestContextScopeGuard() {
......
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