From fccfa03308f68b3d5017a398030a6271b89587ec Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 3 Oct 2017 05:05:15 -0700 Subject: [PATCH] ircd: Add mutable_buffer ctor to parse::buffer; cleanup parse related. --- include/ircd/parse.h | 38 ++++++++++---------------------------- ircd/http.cc | 9 ++------- ircd/parse.cc | 30 +----------------------------- 3 files changed, 13 insertions(+), 64 deletions(-) diff --git a/include/ircd/parse.h b/include/ircd/parse.h index d70a20ae6..771b8c6b5 100644 --- a/include/ircd/parse.h +++ b/include/ircd/parse.h @@ -45,20 +45,6 @@ struct ircd::parse struct buffer; }; -struct ircd::parse::grammar -{ - static std::map grammars; - - const char *const name; - - private: - decltype(grammars)::const_iterator grammars_it; - - public: - grammar(const char *const &name); - ~grammar() noexcept; -}; - struct ircd::parse::buffer { char *base; // Lowest address of the buffer (const) @@ -74,28 +60,24 @@ struct ircd::parse::buffer void discard(); void remove(); - buffer(const buffer &old, char *const &start, char *const &stop) - :base{start} - ,parsed{start} - ,read{start + old.unparsed()} + buffer(const buffer &old, const mutable_buffer &mb) + :base{data(mb)} + ,parsed{data(mb)} + ,read{data(mb) + old.unparsed()} ,stop{stop} { memmove(base, old.base, old.unparsed()); } - buffer(char *const &start, char *const &stop) - :base{start} - ,parsed{start} - ,read{start} - ,stop{stop} + buffer(const mutable_buffer &mb) + :base{data(mb)} + ,parsed{data(mb)} + ,read{data(mb)} + ,stop{data(mb) + ircd::size(mb)} {} template buffer(const buffer &old, char (&buf)[N]) - :buffer{old, buf, buf + N} - {} - - template buffer(char (&buf)[N]) - :buffer{buf, buf + N} + :buffer{old, buf} {} }; diff --git a/ircd/http.cc b/ircd/http.cc index 29e245e9f..ca85369da 100644 --- a/ircd/http.cc +++ b/ircd/http.cc @@ -130,7 +130,6 @@ template struct ircd::http::grammar :qi::grammar -,parse::grammar { template using rule = qi::rule; @@ -218,15 +217,11 @@ struct ircd::http::grammar ,"response" }; - grammar(const rule &top_rule, const char *const &name) + grammar(const rule &top_rule) :grammar::base_type { top_rule } - ,parse::grammar - { - name - } {} }; @@ -236,7 +231,7 @@ struct ircd::http::parser static size_t content_length(const string_view &val); using http::grammar::grammar; - parser(): grammar { grammar::ws, "http.request" } {} + parser(): grammar { grammar::ws } {} } const ircd::http::parser; diff --git a/ircd/parse.cc b/ircd/parse.cc index eaa882e38..092593f73 100644 --- a/ircd/parse.cc +++ b/ircd/parse.cc @@ -19,37 +19,9 @@ * POSSIBILITY OF SUCH DAMAGE. */ -//#include -//#include - -namespace ircd { - -// Registry of grammars. Grammars are usualy static data or modules. -IRCD_INIT_PRIORITY(STD_CONTAINER) -decltype(parse::grammar::grammars) -parse::grammar::grammars +namespace ircd { -}; -} // namespace ircd - -ircd::parse::grammar::grammar(const char *const &name) -:name{name} -,grammars_it{[this, &name] -{ - const auto iit(grammars.emplace(name, this)); - if(!iit.second) - throw grammar_error("Parsing grammar named \"%s\" already exists.", name); - - return iit.first; -}()} -{ -} - -ircd::parse::grammar::~grammar() -noexcept -{ - grammars.erase(grammars_it); }