From c5cbb3ff54119855e63dff9666fd490a92f0db76 Mon Sep 17 00:00:00 2001 From: ipknHama Date: Fri, 15 Aug 2014 11:06:00 +0900 Subject: remove shared_ptr for performance --- include/parser.h | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'include/parser.h') 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 headers; std::string body; - http_parser_settings settings_; - Handler* handler_; }; } -- cgit v1.2.3-54-g00ecf