Skip to content

Commit d7daa62

Browse files
committed
bigint move impl to details
1 parent c8e4b1c commit d7daa62

File tree

1 file changed

+50
-46
lines changed

1 file changed

+50
-46
lines changed

include/jsoncons/utility/bigint.hpp

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,49 +1985,7 @@ basic_bigint<Allocator> bsqrt(const basic_bigint<Allocator>& a)
19851985
return x < q ? x : q;
19861986
}
19871987

1988-
template <typename CharT, typename Allocator>
1989-
to_bigint_result<CharT> to_bigint(const CharT* data, std::size_t length,
1990-
basic_bigint<Allocator>& value, const Allocator& alloc)
1991-
{
1992-
if (JSONCONS_UNLIKELY(length == 0))
1993-
{
1994-
return to_bigint_result<CharT>(data, std::errc::invalid_argument);
1995-
}
1996-
1997-
if (*data == '-')
1998-
{
1999-
return to_bigint(data+1, length-1, true, value, alloc);
2000-
}
2001-
else
2002-
{
2003-
return to_bigint(data, length, false, value, alloc);
2004-
}
2005-
}
2006-
2007-
template <typename CharT>
2008-
to_bigint_result<CharT> to_bigint(const CharT* s, basic_bigint<std::allocator<uint64_t>>& value)
2009-
{
2010-
return to_bigint(s, std::char_traits<CharT>::length(s), value);
2011-
}
2012-
2013-
template <typename CharT>
2014-
to_bigint_result<CharT> to_bigint(const CharT* data, std::size_t length,
2015-
basic_bigint<std::allocator<uint64_t>>& value)
2016-
{
2017-
if (JSONCONS_UNLIKELY(length == 0))
2018-
{
2019-
return to_bigint_result<CharT>(data, std::errc::invalid_argument);
2020-
}
2021-
2022-
if (*data == '-')
2023-
{
2024-
return to_bigint(data+1, length-1, true, value, std::allocator<uint64_t>{});
2025-
}
2026-
else
2027-
{
2028-
return to_bigint(data, length, false, value, std::allocator<uint64_t>{});
2029-
}
2030-
}
1988+
namespace detail {
20311989

20321990
template <typename CharT, typename Allocator>
20331991
to_bigint_result<CharT> to_bigint(const CharT* data, std::size_t length,
@@ -2060,8 +2018,8 @@ to_bigint_result<CharT> to_bigint(const CharT* data, std::size_t length,
20602018
}
20612019
else
20622020
{
2063-
std::size_t num_bits = (std::size_t)(((num_digits*detail::bits_per_digit[10]) >> 10) + 1);
2064-
num_words = (num_bits+63) >> 6;
2021+
std::size_t num_bits = (std::size_t)(((num_digits * detail::bits_per_digit[10]) >> 10) + 1);
2022+
num_words = (num_bits + 63) >> 6;
20652023
}
20662024

20672025
basic_bigint<Allocator> v(0, alloc);
@@ -2075,7 +2033,7 @@ to_bigint_result<CharT> to_bigint(const CharT* data, std::size_t length,
20752033
v = (v * 10u) + (word_type)(c - '0');
20762034
break;
20772035
default:
2078-
return to_bigint_result<CharT>(data+i, std::errc::invalid_argument);
2036+
return to_bigint_result<CharT>(data + i, std::errc::invalid_argument);
20792037
}
20802038
}
20812039

@@ -2094,6 +2052,52 @@ to_bigint_result<CharT> to_bigint(const CharT* data, std::size_t length,
20942052
return to_bigint_result<CharT>(last, std::errc{});
20952053
}
20962054

2055+
} // namespace detail
2056+
2057+
template <typename CharT, typename Allocator>
2058+
to_bigint_result<CharT> to_bigint(const CharT* data, std::size_t length,
2059+
basic_bigint<Allocator>& value, const Allocator& alloc)
2060+
{
2061+
if (JSONCONS_UNLIKELY(length == 0))
2062+
{
2063+
return to_bigint_result<CharT>(data, std::errc::invalid_argument);
2064+
}
2065+
2066+
if (*data == '-')
2067+
{
2068+
return jsoncons::detail::to_bigint(data + 1, length - 1, true, value, alloc);
2069+
}
2070+
else
2071+
{
2072+
return jsoncons::detail::to_bigint(data, length, false, value, alloc);
2073+
}
2074+
}
2075+
2076+
template <typename CharT>
2077+
to_bigint_result<CharT> to_bigint(const CharT* s, basic_bigint<std::allocator<uint64_t>>& value)
2078+
{
2079+
return to_bigint(s, std::char_traits<CharT>::length(s), value);
2080+
}
2081+
2082+
template <typename CharT>
2083+
to_bigint_result<CharT> to_bigint(const CharT* data, std::size_t length,
2084+
basic_bigint<std::allocator<uint64_t>>& value)
2085+
{
2086+
if (JSONCONS_UNLIKELY(length == 0))
2087+
{
2088+
return to_bigint_result<CharT>(data, std::errc::invalid_argument);
2089+
}
2090+
2091+
if (*data == '-')
2092+
{
2093+
return jsoncons::detail::to_bigint(data+1, length-1, true, value, std::allocator<uint64_t>{});
2094+
}
2095+
else
2096+
{
2097+
return jsoncons::detail::to_bigint(data, length, false, value, std::allocator<uint64_t>{});
2098+
}
2099+
}
2100+
20972101
using bigint = basic_bigint<std::allocator<uint64_t>>;
20982102

20992103
} // namespace jsoncons

0 commit comments

Comments
 (0)