mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-04 14:14:09 +00:00
rewrite string construction (performance improved)
This commit is contained in:
parent
ece20bf8ef
commit
165b9ee1cd
6 changed files with 48 additions and 68 deletions
|
@ -4,8 +4,6 @@
|
|||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/index_tuple.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/string/char_traits.hpp>
|
||||
#include <sprout/string/string.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
|
@ -14,40 +12,13 @@ namespace sprout {
|
|||
//
|
||||
// make_string
|
||||
//
|
||||
namespace detail {
|
||||
template<typename T, std::size_t N, sprout::index_t... Indexes>
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string<T, N - 1> make_string_impl_1(
|
||||
sprout::array<T, N> const& arr,
|
||||
std::size_t n,
|
||||
sprout::index_tuple<Indexes...>
|
||||
)
|
||||
{
|
||||
return sprout::basic_string<T, N - 1>{{(Indexes < n ? arr[Indexes] : T())...}, n};
|
||||
}
|
||||
template<typename T, std::size_t N, sprout::index_t... Indexes>
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string<T, N - 1> make_string_impl(
|
||||
sprout::array<T, N> const& arr,
|
||||
sprout::index_tuple<Indexes...>
|
||||
)
|
||||
{
|
||||
return sprout::detail::make_string_impl_1(
|
||||
arr,
|
||||
sprout::char_traits<T>::length(arr.begin()),
|
||||
sprout::index_tuple<Indexes...>()
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
template<typename T, typename... Types>
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string<typename std::decay<T>::type, 1 + sizeof...(Types)>
|
||||
make_string(T&& t, Types&&... args) {
|
||||
return sprout::detail::make_string_impl(
|
||||
sprout::make_array<typename std::decay<T>::type>(
|
||||
sprout::forward<T>(t),
|
||||
sprout::forward<Types>(args)...,
|
||||
typename std::decay<T>::type()
|
||||
),
|
||||
typename sprout::index_range<0, 1 + sizeof...(Types)>::type()
|
||||
);
|
||||
typedef sprout::detail::make_construct_impl<
|
||||
sprout::basic_string<typename std::decay<T>::type, 1 + sizeof...(Types)>
|
||||
> impl_type;
|
||||
return impl_type::make(sprout::forward<T>(t), sprout::forward<Types>(args)...);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -61,13 +32,10 @@ namespace sprout {
|
|||
template<typename T, typename... Types>
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string<typename std::decay<T>::type, sizeof...(Types)>
|
||||
make_string_as(Types&&... args) {
|
||||
return sprout::detail::make_string_impl(
|
||||
sprout::make_array<typename std::decay<T>::type>(
|
||||
sprout::forward<Types>(args)...,
|
||||
typename std::decay<T>::type()
|
||||
),
|
||||
typename sprout::index_range<0, 1 + sizeof...(Types)>::type()
|
||||
);
|
||||
typedef sprout::detail::make_construct_impl<
|
||||
sprout::basic_string<typename std::decay<T>::type, sizeof...(Types)>
|
||||
> impl_type;
|
||||
return impl_type::make(sprout::forward<Types>(args)...);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue