Skip to content

Commit

Permalink
bigint test
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Dec 18, 2023
1 parent d86fb97 commit d62cb57
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions include/jsoncons/bigint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,16 +504,26 @@ class basic_bigint : protected detail::basic_bigint_base<Allocator>
uint64_t* end() { return begin() + length(); }
const uint64_t* end() const { return begin() + length(); }

void resize(size_type n)
void resize(size_type new_length)
{
size_type len_old = common_stor_.length_;
reserve(n);
common_stor_.length_ = n;
size_type old_length = common_stor_.length_;
reserve(new_length);
common_stor_.length_ = new_length;

uint64_t* a = data();
for (size_type i = len_old; i < n; ++i)
if (old_length < new_length)
{
a[i] = 0;
if (is_dynamic())
{
std::memset(dynamic_stor_.data_+old_length, 0, size_type((new_length-old_length)*sizeof(uint64_t)));
}
else
{
JSONCONS_ASSERT(new_length <= 2);
for (size_type i = old_length; i < 2; ++i)
{
short_stor_.values_[i] = 0;
}
}
}
}

Expand Down Expand Up @@ -875,9 +885,21 @@ class basic_bigint : protected detail::basic_bigint_base<Allocator>
*p-- &= *q--;
}

if ( old_length > length() )
const size_type new_length = length();
if ( old_length > new_length )
{
memset( data() + length(), 0, size_type(old_length - length()*sizeof(uint64_t)) );
if (is_dynamic())
{
std::memset( dynamic_stor_.data_ + new_length, 0, size_type(old_length - new_length*sizeof(uint64_t)) );
}
else
{
JSONCONS_ASSERT(new_length <= 2);
for (size_type i = new_length; i < 2; ++i)
{
short_stor_.values_[i] = 0;
}
}
}

reduce();
Expand Down

0 comments on commit d62cb57

Please sign in to comment.