Skip to content

Commit 058003e

Browse files
Merge pull request ceph#60994 from MaxKellermann/formatter
Formatter code cleanup Reviewed-by: Patrick Donnelly <[email protected]>
2 parents 3ec88df + 1ae2259 commit 058003e

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

src/common/Formatter.cc

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ FormatterAttrs::FormatterAttrs(const char *attr, ...)
8585
if (!val)
8686
break;
8787

88-
attrs.push_back(make_pair(std::string(s), std::string(val)));
88+
attrs.emplace_back(s, val);
8989
s = va_arg(ap, char *);
9090
} while (s);
9191
va_end(ap);
@@ -607,13 +607,11 @@ void XMLFormatter::write_bin_data(const char* buff, int buf_len)
607607
m_ss.seekg(buf_len);
608608
}
609609

610-
void XMLFormatter::get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str)
610+
void XMLFormatter::get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str) const
611611
{
612612
CachedStackStringStream css;
613613

614-
for (std::list<std::pair<std::string, std::string> >::const_iterator iter = attrs->attrs.begin();
615-
iter != attrs->attrs.end(); ++iter) {
616-
std::pair<std::string, std::string> p = *iter;
614+
for (const auto &p : attrs->attrs) {
617615
*css << " " << p.first << "=" << "\"" << p.second << "\"";
618616
}
619617

@@ -874,9 +872,9 @@ size_t TableFormatter::m_vec_index(std::string_view name)
874872
std::string TableFormatter::get_section_name(std::string_view name)
875873
{
876874
std::string t_name{name};
877-
for (size_t i = 0; i < m_section.size(); i++) {
875+
for (const auto &i : m_section) {
878876
t_name.insert(0, ":");
879-
t_name.insert(0, m_section[i]);
877+
t_name.insert(0, i);
880878
}
881879
if (m_section_open) {
882880
std::stringstream lss;
@@ -996,13 +994,11 @@ void TableFormatter::write_raw_data(const char *data) {
996994
// not supported
997995
}
998996

999-
void TableFormatter::get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str)
997+
void TableFormatter::get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str) const
1000998
{
1001999
CachedStackStringStream css;
10021000

1003-
for (std::list<std::pair<std::string, std::string> >::const_iterator iter = attrs->attrs.begin();
1004-
iter != attrs->attrs.end(); ++iter) {
1005-
std::pair<std::string, std::string> p = *iter;
1001+
for (const auto &p : attrs->attrs) {
10061002
*css << " " << p.first << "=" << "\"" << p.second << "\"";
10071003
}
10081004

src/common/Formatter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ namespace ceph {
328328
void open_section_in_ns(std::string_view name, const char *ns, const FormatterAttrs *attrs);
329329
void finish_pending_string();
330330
void print_spaces();
331-
void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str);
331+
void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str) const;
332332
char to_lower_underscore(char c) const;
333333
std::string get_xml_name(std::string_view name) const;
334334

@@ -376,7 +376,7 @@ namespace ceph {
376376

377377
int get_len() const override;
378378
void write_raw_data(const char *data) override;
379-
void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str);
379+
void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str) const;
380380

381381
private:
382382
template <class T>

0 commit comments

Comments
 (0)