Skip to content

Commit a409503

Browse files
Merge pull request #2734 from secondlife/nat/llconvert-nop
Try to eliminate the runtime cost of `ll_convert_to<T>(const T&)`.
2 parents b15c194 + c7e9c5d commit a409503

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

indra/llcommon/llstring.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,13 @@ class ll_convert
550550
public:
551551
ll_convert(const FROM& ref): mRef(ref) {}
552552

553-
template <typename TO>
553+
inline operator const FROM&() const
554+
{
555+
return mRef;
556+
}
557+
558+
template <typename TO,
559+
std::enable_if_t<! std::is_same_v<std::decay_t<TO>, std::decay_t<FROM>>, bool> =true>
554560
inline operator TO() const
555561
{
556562
return ll_convert_impl<TO, std::decay_t<const FROM>>()(mRef);
@@ -559,7 +565,15 @@ class ll_convert
559565

560566
// When the TO type must be explicit, use a function template to get
561567
// ll_convert_to<TO>(from_value) API.
562-
template<typename TO, typename FROM>
568+
template<typename SAME>
569+
const SAME& ll_convert_to(const SAME& in)
570+
{
571+
return in;
572+
}
573+
574+
template<typename TO,
575+
typename FROM,
576+
std::enable_if_t<! std::is_same_v<std::decay_t<TO>, std::decay_t<FROM>>, bool> =true>
563577
TO ll_convert_to(const FROM& in)
564578
{
565579
return ll_convert_impl<TO, std::decay_t<const FROM>>()(in);

0 commit comments

Comments
 (0)