Commit 27da08ee authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

nghttpx: Add inline LogFragment ctor

parent 0a6877d0
...@@ -323,13 +323,6 @@ int parse_int(T *dest, const char *opt, const char *optarg) { ...@@ -323,13 +323,6 @@ int parse_int(T *dest, const char *opt, const char *optarg) {
return 0; return 0;
} }
namespace {
LogFragment make_log_fragment(LogFragmentType type,
std::unique_ptr<char[]> value = nullptr) {
return LogFragment{type, std::move(value)};
}
} // namespace
namespace { namespace {
bool var_token(char c) { bool var_token(char c) {
return util::isAlpha(c) || util::isDigit(c) || c == '_'; return util::isAlpha(c) || util::isDigit(c) || c == '_';
...@@ -418,19 +411,17 @@ std::vector<LogFragment> parse_log_format(const char *optarg) { ...@@ -418,19 +411,17 @@ std::vector<LogFragment> parse_log_format(const char *optarg) {
} }
if (literal_start < var_start) { if (literal_start < var_start) {
res.push_back(make_log_fragment(SHRPX_LOGF_LITERAL, res.emplace_back(SHRPX_LOGF_LITERAL, strcopy(literal_start, var_start));
strcopy(literal_start, var_start)));
} }
literal_start = p; literal_start = p;
if (value == nullptr) { if (value == nullptr) {
res.push_back(make_log_fragment(type)); res.emplace_back(type);
continue; continue;
} }
res.push_back( res.emplace_back(type, strcopy(value, var_name + var_namelen));
make_log_fragment(type, strcopy(value, var_name + var_namelen)));
auto &v = res.back().value; auto &v = res.back().value;
for (size_t i = 0; v[i]; ++i) { for (size_t i = 0; v[i]; ++i) {
if (v[i] == '_') { if (v[i] == '_') {
...@@ -440,8 +431,7 @@ std::vector<LogFragment> parse_log_format(const char *optarg) { ...@@ -440,8 +431,7 @@ std::vector<LogFragment> parse_log_format(const char *optarg) {
} }
if (literal_start != eop) { if (literal_start != eop) {
res.push_back( res.emplace_back(SHRPX_LOGF_LITERAL, strcopy(literal_start, eop));
make_log_fragment(SHRPX_LOGF_LITERAL, strcopy(literal_start, eop)));
} }
return res; return res;
......
...@@ -123,6 +123,8 @@ enum LogFragmentType { ...@@ -123,6 +123,8 @@ enum LogFragmentType {
}; };
struct LogFragment { struct LogFragment {
LogFragment(LogFragmentType type, std::unique_ptr<char[]> value = nullptr)
: type(type), value(std::move(value)) {}
LogFragmentType type; LogFragmentType type;
std::unique_ptr<char[]> value; std::unique_ptr<char[]> value;
}; };
......
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