Skip to content

Commit d234d63

Browse files
committed
optimize toString slightly
Also get rid of if constexpr for C++11 compatibility. The else condition results in extra generated code as compilers are not free to promote if to if constexpr.
1 parent 6ee4a16 commit d234d63

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

include/exiv2/types.hpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ enum TypeId {
9595
xmpSeq = 0x10008, //!< XMP sequence type.
9696
langAlt = 0x10009, //!< XMP language alternative type.
9797
invalidTypeId = 0x1fffe, //!< Invalid type id.
98-
lastTypeId = 0x1ffff //!< Last type id.
98+
lastTypeId = 0x1ffff, //!< Last type id.
9999
};
100100

101101
//! Container for binary data
@@ -447,17 +447,26 @@ EXIV2API Rational floatToRationalCast(float f);
447447
*/
448448
template <typename T, typename K, int N>
449449
const T* find(T (&src)[N], const K& key) {
450-
const T* rc = std::find(src, src + N, key);
450+
auto rc = std::find(src, src + N, key);
451451
return rc == src + N ? nullptr : rc;
452452
}
453453

454454
//! Utility function to convert the argument of any type to a string
455455
template <typename T>
456-
std::string toString(const T& arg) {
456+
std::string toStringHelper(const T& arg, std::true_type) {
457+
return std::to_string(arg);
458+
}
459+
460+
template <typename T>
461+
std::string toStringHelper(const T& arg, std::false_type) {
457462
std::ostringstream os;
458463
os << arg;
459464
return os.str();
460465
}
466+
template <typename T>
467+
std::string toString(const T& arg) {
468+
return toStringHelper(arg, std::is_integral<T>());
469+
}
461470

462471
/*!
463472
@brief Utility function to convert a string to a value of type \c T.

0 commit comments

Comments
 (0)