Skip to content

Commit

Permalink
clang-tidy: performance
Browse files Browse the repository at this point in the history
  • Loading branch information
farmerpiki committed Aug 21, 2024
1 parent 91b56fd commit 27d65f0
Show file tree
Hide file tree
Showing 10 changed files with 473 additions and 471 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Checks: 'modernize-*, misc-*, -misc-definitions-in-headers, -misc-non-private-member-variables-in-classes, -misc-no-recursion, -misc-include-cleaner, -misc-use-anonymous-namespace, -modernize-use-trailing-return-type, -modernize-use-nodiscard, -modernize-use-emplace, -modernize-loop-convert, -modernize-pass-by-value, -modernize-use-equals-delete, -modernize-use-equals-default, -modernize-use-override, -modernize-avoid-c-arrays, -modernize-raw-string-literal, -modernize-concat-nested-namespaces'
Checks: 'performance-*, modernize-*, misc-*, -misc-definitions-in-headers, -misc-non-private-member-variables-in-classes, -misc-no-recursion, -misc-include-cleaner, -misc-use-anonymous-namespace, -modernize-use-trailing-return-type, -modernize-use-nodiscard, -modernize-use-emplace, -modernize-loop-convert, -modernize-pass-by-value, -modernize-use-equals-delete, -modernize-use-equals-default, -modernize-use-override, -modernize-avoid-c-arrays, -modernize-raw-string-literal, -modernize-concat-nested-namespaces, -performance-inefficient-string-concatenation'
6 changes: 3 additions & 3 deletions source/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct source_line
{
std::string text;

enum class category { empty, preprocessor, comment, import, cpp1, cpp2, rawstring };
enum class category : std::uint8_t { empty, preprocessor, comment, import, cpp1, cpp2, rawstring };
category cat;

bool all_tokens_are_densely_spaced = true; // to be overridden in lexing if they're not
Expand Down Expand Up @@ -128,7 +128,7 @@ struct source_position

struct comment
{
enum class comment_kind { line_comment = 0, stream_comment };
enum class comment_kind : std::uint8_t { line_comment = 0, stream_comment };

comment_kind kind;
source_position start;
Expand All @@ -141,7 +141,7 @@ struct comment
struct string_parts {
struct cpp_code { std::string text; };
struct raw_string { std::string text; };
enum adds_sequences { no_ends = 0, on_the_beginning = 1, on_the_end = 2, on_both_ends = 3 };
enum adds_sequences : std::uint8_t { no_ends = 0, on_the_beginning = 1, on_the_end = 2, on_both_ends = 3 };

string_parts(const std::string& beginseq,
const std::string& endseq,
Expand Down
2 changes: 1 addition & 1 deletion source/cppfront.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ auto main(
}
else {
std::cerr << arg.text << " - ambiguous compiler flag name, did you mean one of these?\n";
for (auto a : ambiguous) {
for (auto const &a : ambiguous) {
std::cerr << " " << arg.text.front() << a << "\n";
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ class braces_tracker
//
// line current line being processed
//
enum class preprocessor_conditional {
enum class preprocessor_conditional : std::uint8_t {
none = 0, pre_if, pre_else, pre_endif
};
auto starts_with_preprocessor_if_else_endif(
Expand Down Expand Up @@ -635,7 +635,7 @@ auto process_cpp_line(
i+=2;
if (i < ssize(line) - 1)
{
if (auto paren_pos = line.find("(", i);
if (auto paren_pos = line.find('(', i);
paren_pos != line.npos
)
{
Expand Down
4 changes: 2 additions & 2 deletions source/lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,7 @@ auto lex_line(
auto R_pos = i + 1;
auto seq_pos = i + 3;

if (auto paren_pos = line.find("(", seq_pos); paren_pos != line.npos) {
if (auto paren_pos = line.find('(', seq_pos); paren_pos != line.npos) {
auto opening_seq = line.substr(i, paren_pos - i + 1);
auto closing_seq = ")"+line.substr(seq_pos, paren_pos-seq_pos)+"\"";

Expand Down Expand Up @@ -1717,7 +1717,7 @@ auto lex_line(
if (peek(j-2) == 'R') {
auto seq_pos = i + j;

if (auto paren_pos = line.find("(", seq_pos); paren_pos != line.npos) {
if (auto paren_pos = line.find('(', seq_pos); paren_pos != line.npos) {
auto opening_seq = line.substr(i, paren_pos - i + 1);
auto closing_seq = ")"+line.substr(seq_pos, paren_pos-seq_pos)+"\"";

Expand Down
20 changes: 10 additions & 10 deletions source/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct template_argument;

struct primary_expression_node
{
enum active { empty=0, identifier, expression_list, id_expression, declaration, inspect, literal };
enum active : std::uint8_t { empty=0, identifier, expression_list, id_expression, declaration, inspect, literal };
std::variant<
std::monostate,
token const*,
Expand Down Expand Up @@ -666,7 +666,7 @@ auto binary_expression_node<Name, Term>::is_standalone_expression() const
}


enum class passing_style { in=0, copy, inout, out, move, forward, invalid };
enum class passing_style : std::uint8_t { in=0, copy, inout, out, move, forward, invalid };
auto to_passing_style(token const& t) -> passing_style {
if (t.type() == lexeme::Identifier) {
if (t == "in" ) { return passing_style::in; }
Expand Down Expand Up @@ -1152,7 +1152,7 @@ struct template_args_tag { };

struct template_argument
{
enum active { empty=0, expression, type_id };
enum active : std::uint8_t { empty=0, expression, type_id };
source_position comma;
std::variant<
std::monostate,
Expand Down Expand Up @@ -1338,7 +1338,7 @@ struct type_id_node
int dereference_cnt = {};
token const* suspicious_initialization = {};

enum active { empty=0, qualified, unqualified, function, keyword };
enum active : std::uint8_t { empty=0, qualified, unqualified, function, keyword };
std::variant<
std::monostate,
std::unique_ptr<qualified_id_node>,
Expand Down Expand Up @@ -1660,7 +1660,7 @@ struct id_expression_node
{
source_position pos;

enum active { empty=0, qualified, unqualified };
enum active : std::uint8_t { empty=0, qualified, unqualified };
std::variant<
std::monostate,
std::unique_ptr<qualified_id_node>,
Expand Down Expand Up @@ -2147,7 +2147,7 @@ struct statement_node
// type(s) used in a std::unique_ptr as a member
~statement_node();

enum active { expression=0, compound, selection, declaration, return_, iteration, using_, contract, inspect, jump };
enum active : std::uint8_t { expression=0, compound, selection, declaration, return_, iteration, using_, contract, inspect, jump };
std::variant<
std::unique_ptr<expression_statement_node>,
std::unique_ptr<compound_statement_node>,
Expand Down Expand Up @@ -2275,7 +2275,7 @@ struct parameter_declaration_node
passing_style pass = passing_style::in;
int ordinal = 1;

enum class modifier { none=0, implicit, virtual_, override_, final_ };
enum class modifier : std::uint8_t { none=0, implicit, virtual_, override_, final_ };
modifier mod = modifier::none;

std::unique_ptr<declaration_node> declaration;
Expand Down Expand Up @@ -2446,7 +2446,7 @@ struct function_type_node
passing_style pass = passing_style::move;
};

enum active { empty = 0, id, list };
enum active : std::uint8_t { empty = 0, id, list };
std::variant<
std::monostate,
single_type_id,
Expand Down Expand Up @@ -2809,7 +2809,7 @@ struct alias_node
};


enum class accessibility { default_ = 0, public_, protected_, private_ };
enum class accessibility : std::uint8_t { default_ = 0, public_, protected_, private_ };

auto to_string(accessibility a)
-> std::string
Expand Down Expand Up @@ -3257,7 +3257,7 @@ struct declaration_node
auto parent_is_polymorphic() const -> bool
{ return parent_declaration && parent_declaration->is_polymorphic(); }

enum which {
enum which : std::uint8_t {
functions = 1,
objects = 2,
types = 4,
Expand Down
Loading

0 comments on commit 27d65f0

Please sign in to comment.