Commit 8174190b authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

Use RequestToken in RequestEventBase

Summary: [Folly] Use `RequestToken` in `RequestEventBase` to speed up lookup.

Reviewed By: zhxchen17

Differential Revision: D21529465

fbshipit-source-id: eaaef7b48be2c5a8d76fb5f4a5293f7db7e68bed
parent ed5983fe
...@@ -84,7 +84,7 @@ class RequestEventBase : public RequestData { ...@@ -84,7 +84,7 @@ class RequestEventBase : public RequestData {
public: public:
static EventBase* get() { static EventBase* get() {
auto data = dynamic_cast<RequestEventBase*>( auto data = dynamic_cast<RequestEventBase*>(
RequestContext::get()->getContextData(kContextDataName)); RequestContext::get()->getContextData(token()));
if (!data) { if (!data) {
return nullptr; return nullptr;
} }
...@@ -93,8 +93,7 @@ class RequestEventBase : public RequestData { ...@@ -93,8 +93,7 @@ class RequestEventBase : public RequestData {
static void set(EventBase* eb) { static void set(EventBase* eb) {
RequestContext::get()->setContextData( RequestContext::get()->setContextData(
kContextDataName, token(), std::unique_ptr<RequestEventBase>(new RequestEventBase(eb)));
std::unique_ptr<RequestEventBase>(new RequestEventBase(eb)));
} }
bool hasCallback() override { bool hasCallback() override {
...@@ -102,6 +101,11 @@ class RequestEventBase : public RequestData { ...@@ -102,6 +101,11 @@ class RequestEventBase : public RequestData {
} }
private: private:
FOLLY_EXPORT static RequestToken const& token() {
static RequestToken const token(kContextDataName);
return token;
}
explicit RequestEventBase(EventBase* eb) : eb_(eb) {} explicit RequestEventBase(EventBase* eb) : eb_(eb) {}
EventBase* eb_; EventBase* eb_;
static constexpr const char* kContextDataName{"EventBase"}; static constexpr const char* kContextDataName{"EventBase"};
......
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