optimizations
This commit is contained in:
parent
dc513839bd
commit
25bbbfdbcc
@ -20,6 +20,7 @@ namespace mstch {
|
||||
private:
|
||||
render_context& context;
|
||||
};
|
||||
|
||||
render_context(
|
||||
const mstch::object& object,
|
||||
const std::map<std::string,template_type>& partials);
|
||||
|
@ -18,8 +18,7 @@ std::string state::in_section::render(render_context& ctx, const token& token) {
|
||||
std::string out;
|
||||
if (!boost::apply_visitor(visitor::is_node_empty(), section_node))
|
||||
out = boost::apply_visitor(
|
||||
visitor::render_section(ctx, section),
|
||||
section_node);
|
||||
visitor::render_section(ctx, section), section_node);
|
||||
ctx.set_state<outside_section>();
|
||||
return out;
|
||||
} else {
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "render_context.hpp"
|
||||
|
||||
using namespace mstch;
|
||||
using flag = visitor::render_node::flag;
|
||||
|
||||
std::string state::outside_section::render(
|
||||
render_context& ctx, const token& token)
|
||||
@ -17,13 +18,10 @@ std::string state::outside_section::render(
|
||||
ctx.set_state<in_inverted_section>(token.content());
|
||||
break;
|
||||
case token::type::variable:
|
||||
case token::type::unescaped_variable: {
|
||||
std::set<visitor::render_node::flag> flags{};
|
||||
if (token.token_type() == token::type::variable)
|
||||
flags.insert(visitor::render_node::flag::escape_html);
|
||||
return boost::apply_visitor(
|
||||
visitor::render_node(flags), ctx.get_node(token.content()));
|
||||
}
|
||||
case token::type::unescaped_variable:
|
||||
return boost::apply_visitor(visitor::render_node((token.token_type() ==
|
||||
token::type::variable)?flag::escape_html:flag::none),
|
||||
ctx.get_node(token.content()));
|
||||
case token::type::comment: break;
|
||||
case token::type::text:
|
||||
return token.content();
|
||||
|
@ -33,14 +33,12 @@ void template_type::tokenize(const std::string& t) {
|
||||
else
|
||||
pstate = parse_state::start;
|
||||
} else if(pstate == parse_state::in_del) {
|
||||
if (*it == '{') {
|
||||
if (*it == '{')
|
||||
pstate = parse_state::in_esccontent;
|
||||
} else if (*it == delim_end[0]) {
|
||||
else if (*it == delim_end[0] && (del_pos = 1))
|
||||
pstate = parse_state::in_del_end;
|
||||
del_pos = 1;
|
||||
} else {
|
||||
else
|
||||
pstate = parse_state::in_content;
|
||||
}
|
||||
} else if(pstate == parse_state::in_esccontent && *it == '}') {
|
||||
pstate = parse_state::in_content;
|
||||
} else if(pstate == parse_state::in_content && *it == delim_end[0]) {
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
using namespace mstch;
|
||||
|
||||
visitor::render_node::render_node(std::set<flag> flags): flags(flags) {
|
||||
visitor::render_node::render_node(flag p_flag): m_flag(p_flag) {
|
||||
}
|
||||
|
||||
std::string visitor::render_node::operator()(const boost::blank& blank) const {
|
||||
@ -19,7 +19,7 @@ std::string visitor::render_node::operator()(const bool& b) const {
|
||||
}
|
||||
|
||||
std::string visitor::render_node::operator()(const std::string& str) const {
|
||||
return (flags.find(flag::escape_html) != flags.end())?html_escape(str):str;
|
||||
return (m_flag == flag::escape_html)?html_escape(str):str;
|
||||
}
|
||||
|
||||
std::string visitor::render_node::operator()(const array& arr) const {
|
||||
|
@ -10,8 +10,8 @@ namespace mstch {
|
||||
namespace visitor {
|
||||
class render_node: public boost::static_visitor<std::string> {
|
||||
public:
|
||||
enum class flag { escape_html };
|
||||
render_node(std::set<flag> flags = {});
|
||||
enum class flag { none, escape_html };
|
||||
render_node(flag p_flag = flag::none);
|
||||
std::string operator()(const boost::blank& blank) const;
|
||||
std::string operator()(const int& i) const;
|
||||
std::string operator()(const bool& b) const;
|
||||
@ -21,7 +21,7 @@ namespace mstch {
|
||||
std::string operator()(const string_lambda& lambda) const;
|
||||
std::string operator()(const renderer_lambda& lambda) const;
|
||||
private:
|
||||
std::set<flag> flags;
|
||||
flag m_flag;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,8 @@
|
||||
using namespace mstch;
|
||||
|
||||
visitor::render_section::render_section(
|
||||
render_context& ctx, const template_type& section,std::set<flag> flags):
|
||||
ctx(ctx), section(section), flags(flags)
|
||||
render_context& ctx, const template_type& section, flag p_flag):
|
||||
ctx(ctx), section(section), m_flag(p_flag)
|
||||
{
|
||||
}
|
||||
|
||||
@ -32,12 +32,12 @@ std::string visitor::render_section::operator()(const object& obj) const {
|
||||
|
||||
std::string visitor::render_section::operator()(const array& a) const {
|
||||
std::string out;
|
||||
if(flags.find(flag::keep_array) != flags.end())
|
||||
if(m_flag == flag::keep_array)
|
||||
out += render_context::push(ctx, {{".", a}}).render(section);
|
||||
else
|
||||
for (auto& item: a)
|
||||
out += boost::apply_visitor(
|
||||
render_section(ctx, section, {flag::keep_array}), item);
|
||||
render_section(ctx, section, flag::keep_array), item);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -11,11 +11,11 @@ namespace mstch {
|
||||
namespace visitor {
|
||||
class render_section: public boost::static_visitor<std::string> {
|
||||
public:
|
||||
enum class flag { keep_array };
|
||||
enum class flag { none, keep_array };
|
||||
render_section(
|
||||
render_context& ctx,
|
||||
const template_type& section,
|
||||
std::set<flag> flags = {});
|
||||
flag p_flag = flag::none);
|
||||
std::string operator()(const boost::blank& blank) const;
|
||||
std::string operator()(const int& i) const;
|
||||
std::string operator()(const bool& b) const;
|
||||
@ -27,7 +27,7 @@ namespace mstch {
|
||||
private:
|
||||
render_context& ctx;
|
||||
const template_type& section;
|
||||
std::set<flag> flags;
|
||||
flag m_flag;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user