mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +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
|
@ -8,7 +8,7 @@
|
|||
|
||||
namespace sprout {
|
||||
//
|
||||
// strtol
|
||||
// strtoimax
|
||||
//
|
||||
inline SPROUT_CONSTEXPR std::intmax_t strtoimax(char const* str, char** endptr, int base = 10){
|
||||
return sprout::str_to_int<std::intmax_t>(str, endptr, base);
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
namespace sprout {
|
||||
//
|
||||
// strtoul
|
||||
// strtoumax
|
||||
//
|
||||
inline SPROUT_CONSTEXPR std::uintmax_t strtoumax(char const* str, char** endptr, int base = 10){
|
||||
return sprout::str_to_int<std::uintmax_t>(str, endptr, base);
|
||||
|
|
|
@ -32,8 +32,8 @@ namespace sprout {
|
|||
}
|
||||
template<typename T, std::size_t N, typename Traits, std::size_t N2>
|
||||
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::append_back<
|
||||
sprout::basic_string<T, N, Traits>,
|
||||
sprout::basic_string<T, N2 - 1, Traits>
|
||||
sprout::basic_string<T, N, Traits>,
|
||||
sprout::basic_string<T, N2 - 1, Traits>
|
||||
>::type operator+(
|
||||
sprout::basic_string<T, N, Traits> const& lhs,
|
||||
T const (& rhs)[N2]
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace sprout {
|
|||
template<typename... Args>
|
||||
static SPROUT_CONSTEXPR copied_type make(Args&&... args) {
|
||||
typedef sprout::detail::make_construct_impl<copied_type> impl_type;
|
||||
return impl_type::make(impl_type::length(sprout::forward<Args>(args)...), sprout::forward<Args>(args)...);
|
||||
return impl_type::make(sprout::forward<Args>(args)...);
|
||||
}
|
||||
template<typename Cont, typename... Args>
|
||||
static SPROUT_CONSTEXPR copied_type remake(
|
||||
|
@ -33,7 +33,7 @@ namespace sprout {
|
|||
)
|
||||
{
|
||||
typedef sprout::detail::make_construct_impl<copied_type> impl_type;
|
||||
return impl_type::make(size, sprout::forward<Args>(args)...);
|
||||
return impl_type::make(static_cast<typename copied_type::size_type>(size), sprout::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -8,10 +8,12 @@
|
|||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/index_tuple.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/iterator/reverse_iterator.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/string/char_traits.hpp>
|
||||
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
|
||||
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
|
||||
# include <sprout/iterator/index_iterator.hpp>
|
||||
#endif
|
||||
|
@ -453,35 +455,45 @@ namespace sprout {
|
|||
private:
|
||||
typedef sprout::basic_string<T, N, Traits> copied_type;
|
||||
private:
|
||||
template<std::size_t S>
|
||||
static SPROUT_CONSTEXPR copied_type make_impl(typename copied_type::size_type size) {
|
||||
return copied_type{{}, size};
|
||||
template<std::size_t M>
|
||||
static SPROUT_CONSTEXPR typename copied_type::size_type length_impl(sprout::array<T, M> const& arr) {
|
||||
return NS_SSCRISK_CEL_OR_SPROUT::distance(
|
||||
arr.begin(),
|
||||
NS_SSCRISK_CEL_OR_SPROUT::find(arr.begin(), arr.end(), T())
|
||||
);
|
||||
}
|
||||
template<std::size_t S, typename Head, typename... Tail>
|
||||
static SPROUT_CONSTEXPR typename std::enable_if<
|
||||
S == sizeof...(Tail),
|
||||
copied_type
|
||||
>::type make_impl(typename copied_type::size_type size, Head&& head, Tail&&... tail) {
|
||||
return copied_type{{sprout::forward<Tail>(tail)..., sprout::forward<Head>(head)}, size};
|
||||
}
|
||||
template<std::size_t S, typename Head, typename... Tail>
|
||||
static SPROUT_CONSTEXPR typename std::enable_if<
|
||||
S != sizeof...(Tail),
|
||||
copied_type
|
||||
>::type make_impl(typename copied_type::size_type size, Head&& head, Tail&&... tail) {
|
||||
return make_impl<S + 1>(size, sprout::forward<Tail>(tail)..., S >= size ? T() : sprout::forward<Head>(head));
|
||||
template<typename... Args, sprout::index_t... Indexes>
|
||||
static SPROUT_CONSTEXPR copied_type make_impl(
|
||||
typename copied_type::size_type size,
|
||||
sprout::index_tuple<Indexes...>,
|
||||
Args&&... args
|
||||
)
|
||||
{
|
||||
return copied_type{
|
||||
{(Indexes < size ? sprout::forward<Args>(args) : T())...},
|
||||
size
|
||||
};
|
||||
}
|
||||
public:
|
||||
static SPROUT_CONSTEXPR typename copied_type::size_type length() {
|
||||
return 0;
|
||||
template<typename... Args>
|
||||
static SPROUT_CONSTEXPR typename copied_type::size_type length(Args&&... args) {
|
||||
return length_impl(sprout::make_array<T>(sprout::forward<Args>(args)...));
|
||||
}
|
||||
template<typename... Tail>
|
||||
static SPROUT_CONSTEXPR typename copied_type::size_type length(T const& head, Tail&&... tail) {
|
||||
return !head ? 0 : 1 + length(sprout::forward<Tail>(tail)...);
|
||||
template<typename... Args>
|
||||
static SPROUT_CONSTEXPR copied_type make(Args&&... args) {
|
||||
return make_impl(
|
||||
length(args...),
|
||||
sprout::index_range<0, sizeof...(Args)>::make(),
|
||||
sprout::forward<Args>(args)...
|
||||
);
|
||||
}
|
||||
template<typename... Args>
|
||||
static SPROUT_CONSTEXPR copied_type make(typename copied_type::size_type size, Args&&... args) {
|
||||
return make_impl<0>(size, sprout::forward<Args>(args)...);
|
||||
return make_impl(
|
||||
size,
|
||||
sprout::index_range<0, sizeof...(Args)>::make(),
|
||||
sprout::forward<Args>(args)...
|
||||
);
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
|
|
Loading…
Reference in a new issue