Skip to content

Commit e076378

Browse files
MatzeBmeta-codesync[bot]
authored andcommitted
Hoist forEach option names into static const std::string to avoid per-call temporaries
Reviewed By: DenisYaroshevskiy Differential Revision: D109159609 fbshipit-source-id: 7257538ebda60d7b9ec3abcfb5d29fa2e6fd5e6a
1 parent 3c92d21 commit e076378

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

‎mcrouter/options-template.h‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@ class OPTIONS_NAME : public McrouterOptionsBase {
3838
void(const std::string&, McrouterOptionData::Type, const boost::any&)>
3939
f) const override {
4040
#undef MCROUTER_OPTION
41-
#define MCROUTER_OPTION(_type, _name, _f, _l, _s, _d, _Type) \
42-
f(#_name, \
43-
McrouterOptionData::Type::_Type, \
44-
boost::any(const_cast<_type*>(&_name)));
41+
#define MCROUTER_OPTION(_type, _name, _f, _l, _s, _d, _Type) \
42+
{ \
43+
static const folly::Indestructible<std::string> _name##_optionName{ \
44+
#_name}; \
45+
f(*_name##_optionName, \
46+
McrouterOptionData::Type::_Type, \
47+
boost::any(const_cast<_type*>(&_name))); \
48+
}
4549

4650
#include OPTIONS_FILE
4751
}

‎mcrouter/options.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include <boost/any.hpp>
1616

17+
#include <folly/Indestructible.h>
18+
1719
#include "mcrouter/RoutingPrefix.h"
1820
#include "mcrouter/config.h"
1921

0 commit comments

Comments
 (0)