Skip to content

Commit 7cf7957

Browse files
committed
Remove init methods, simplify const usage, simplify check function, return early based on named_arg_index
1 parent 9800147 commit 7cf7957

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

include/fmt/base.h

+7-9
Original file line numberDiff line numberDiff line change
@@ -1060,20 +1060,18 @@ template <typename... Args> constexpr auto count_static_named_args() -> int {
10601060
}
10611061

10621062
template <typename Char> struct named_arg_info {
1063-
FMT_CONSTEXPR named_arg_info() : name(nullptr), id(0) {}
1064-
FMT_CONSTEXPR named_arg_info(const Char* a_name, const int an_id)
1065-
: name(a_name), id(an_id) {}
10661063
const Char* name;
10671064
int id;
10681065
};
10691066

10701067
template <typename Char>
10711068
FMT_CONSTEXPR void check_for_duplicate(
1072-
const named_arg_info<Char>* const named_args, const int named_arg_index,
1073-
const Char* const arg_name) {
1074-
const basic_string_view<Char> arg_name_view(arg_name);
1069+
named_arg_info<Char>* named_args, int named_arg_index,
1070+
basic_string_view<Char> arg_name) {
1071+
if (named_arg_index <= 0) return;
1072+
10751073
for (auto i = 0; i < named_arg_index; ++i) {
1076-
if (basic_string_view<Char>(named_args[i].name) == arg_name_view) {
1074+
if (basic_string_view<Char>(named_args[i].name) == arg_name) {
10771075
report_error("duplicate named args found");
10781076
}
10791077
}
@@ -1087,7 +1085,7 @@ void init_named_arg(named_arg_info<Char>*, int& arg_index, int&, const T&) {
10871085
template <typename Char, typename T, FMT_ENABLE_IF(is_named_arg<T>::value)>
10881086
void init_named_arg(named_arg_info<Char>* named_args, int& arg_index,
10891087
int& named_arg_index, const T& arg) {
1090-
check_for_duplicate(named_args, named_arg_index, arg.name);
1088+
check_for_duplicate<Char>(named_args, named_arg_index, arg.name);
10911089
named_args[named_arg_index++] = {arg.name, arg_index++};
10921090
}
10931091

@@ -1101,7 +1099,7 @@ template <typename T, typename Char,
11011099
FMT_ENABLE_IF(is_static_named_arg<T>::value)>
11021100
FMT_CONSTEXPR void init_static_named_arg(named_arg_info<Char>* named_args,
11031101
int& arg_index, int& named_arg_index) {
1104-
check_for_duplicate(named_args, named_arg_index, T::name);
1102+
check_for_duplicate<Char>(named_args, named_arg_index, T::name);
11051103
named_args[named_arg_index++] = {T::name, arg_index++};
11061104
}
11071105

0 commit comments

Comments
 (0)