Skip to content

Commit 962a8d2

Browse files
committed
use temporary string_view and starts_with method
1 parent 9c4df8e commit 962a8d2

File tree

1 file changed

+13
-11
lines changed
  • Framework/Core/include/Framework

1 file changed

+13
-11
lines changed

Framework/Core/include/Framework/ASoA.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,37 +2014,39 @@ concept persistent_with_common_getter = is_persistent_v<T> && requires(T t) {
20142014
};
20152015

20162016
template <typename R, typename T, persistent_with_common_getter<R> C>
2017-
ColumnGetterFunction<R, T> createGetterPtr(const std::string_view& columnLabel)
2017+
ColumnGetterFunction<R, T> createGetterPtr(const std::string_view& targetColumnLabel)
20182018
{
2019-
return columnLabel == C::columnLabel() ? &getColumnValue<R, T, C> : nullptr;
2019+
return targetColumnLabel == C::columnLabel() ? &getColumnValue<R, T, C> : nullptr;
20202020
}
20212021

20222022
template <typename R, typename T, dynamic_with_common_getter<R> C>
2023-
ColumnGetterFunction<R, T> createGetterPtr(const std::string_view& columnLabel)
2023+
ColumnGetterFunction<R, T> createGetterPtr(const std::string_view& targetColumnLabel)
20242024
{
2025+
std::string_view columnLabel(C::columnLabel());
2026+
20252027
// allows user to use consistent formatting (with prefix) of all column labels
20262028
// by default there isn't 'f' prefix for dynamic column labels
2027-
if (columnLabel.size() > 1 && columnLabel.substr(1) == C::columnLabel()) {
2029+
if (targetColumnLabel.starts_with("f") && targetColumnLabel.substr(1) == columnLabel) {
20282030
return &getColumnValue<R, T, C>;
20292031
}
20302032

20312033
// check also exact match if user is aware of prefix missing
2032-
if (columnLabel == C::columnLabel()) {
2034+
if (targetColumnLabel == columnLabel) {
20332035
return &getColumnValue<R, T, C>;
20342036
}
20352037

20362038
return nullptr;
20372039
}
20382040

20392041
template <typename R, typename T, typename... Cs>
2040-
ColumnGetterFunction<R, T> getColumnGetterByLabel(o2::framework::pack<Cs...>, const std::string_view& columnLabel)
2042+
ColumnGetterFunction<R, T> getColumnGetterByLabel(o2::framework::pack<Cs...>, const std::string_view& targetColumnLabel)
20412043
{
20422044
ColumnGetterFunction<R, T> func;
20432045

2044-
(void)((func = createGetterPtr<R, T, Cs>(columnLabel), func) || ...);
2046+
(void)((func = createGetterPtr<R, T, Cs>(targetColumnLabel), func) || ...);
20452047

20462048
if (!func) {
2047-
throw framework::runtime_error_f("Getter for \"%s\" not found", columnLabel);
2049+
throw framework::runtime_error_f("Getter for \"%s\" not found", targetColumnLabel);
20482050
}
20492051

20502052
return func;
@@ -2054,15 +2056,15 @@ template <typename T, typename R>
20542056
using with_common_getter_t = typename std::conditional<persistent_with_common_getter<T, R> || dynamic_with_common_getter<T, R>, std::true_type, std::false_type>::type;
20552057

20562058
template <typename R, typename T>
2057-
ColumnGetterFunction<R, typename T::iterator> getColumnGetterByLabel(const std::string_view& columnLabel)
2059+
ColumnGetterFunction<R, typename T::iterator> getColumnGetterByLabel(const std::string_view& targetColumnLabel)
20582060
{
20592061
using TypesWithCommonGetter = o2::framework::selected_pack_multicondition<with_common_getter_t, framework::pack<R>, typename T::columns>;
20602062

2061-
if (columnLabel.size() == 0) {
2063+
if (targetColumnLabel.size() == 0) {
20622064
throw framework::runtime_error("columnLabel: must not be empty");
20632065
}
20642066

2065-
return getColumnGetterByLabel<R, typename T::iterator>(TypesWithCommonGetter{}, columnLabel);
2067+
return getColumnGetterByLabel<R, typename T::iterator>(TypesWithCommonGetter{}, targetColumnLabel);
20662068
}
20672069
} // namespace row_helpers
20682070
} // namespace o2::soa

0 commit comments

Comments
 (0)