aboutsummaryrefslogtreecommitdiffstats
path: root/include/parser.h
diff options
context:
space:
mode:
authoripknHama <ipknhama@gmail.com>2014-08-15 11:06:00 +0900
committeripknHama <ipknhama@gmail.com>2014-08-15 11:06:00 +0900
commitc5cbb3ff54119855e63dff9666fd490a92f0db76 (patch)
tree8738295afc8e3effd3a631731489ebd0cfdd8832 /include/parser.h
parentf91af402f7bb2a3e3cae724512181cbf92d5a918 (diff)
downloadcrow-c5cbb3ff54119855e63dff9666fd490a92f0db76.tar.gz
crow-c5cbb3ff54119855e63dff9666fd490a92f0db76.zip
remove shared_ptr for performance
Diffstat (limited to 'include/parser.h')
-rw-r--r--include/parser.h24
1 files changed, 11 insertions, 13 deletions
diff --git a/include/parser.h b/include/parser.h
index f504248..1b8240f 100644
--- a/include/parser.h
+++ b/include/parser.h
@@ -82,7 +82,15 @@ namespace crow
return 0;
}
HTTPParser(Handler* handler) :
- settings_ {
+ handler_(handler)
+ {
+ http_parser_init(this, HTTP_REQUEST);
+ }
+
+ // return false on error
+ bool feed(const char* buffer, int length)
+ {
+ const static http_parser_settings settings_{
on_message_begin,
on_url,
nullptr,
@@ -91,23 +99,15 @@ namespace crow
on_headers_complete,
on_body,
on_message_complete,
- },
- handler_(handler)
- {
- http_parser_init(this, HTTP_REQUEST);
- }
+ };
- // return false on error
- bool feed(const char* buffer, int length)
- {
int nparsed = http_parser_execute(this, &settings_, buffer, length);
return nparsed == length;
}
bool done()
{
- int nparsed = http_parser_execute(this, &settings_, nullptr, 0);
- return nparsed == 0;
+ return feed(nullptr, 0);
}
void clear()
@@ -147,8 +147,6 @@ namespace crow
std::unordered_map<std::string, std::string> headers;
std::string body;
- http_parser_settings settings_;
-
Handler* handler_;
};
}