nghttpx: Add inline LogFragment ctor

This commit is contained in:
Tatsuhiro Tsujikawa 2015-07-14 22:43:02 +09:00
parent 0a6877d091
commit 27da08ee68
2 changed files with 6 additions and 14 deletions

View File

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

View File

@ -123,6 +123,8 @@ enum LogFragmentType {
};
struct LogFragment {
LogFragment(LogFragmentType type, std::unique_ptr<char[]> value = nullptr)
: type(type), value(std::move(value)) {}
LogFragmentType type;
std::unique_ptr<char[]> value;
};