Skip to content

Commit

Permalink
🔨 trying to fix memory issue with valarray
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Aug 27, 2017
1 parent 0e94ba8 commit 15e757c
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/json.hpp
Expand Up @@ -667,11 +667,10 @@ struct external_constructor<value_t::array>
enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0>
static void construct(BasicJsonType& j, const std::valarray<T>& arr)
{
using std::begin;
using std::end;
j.m_type = value_t::array;
j.m_value = value_t::array;
j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
j.m_value.array->resize(arr.size());
std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin());
j.assert_invariant();
}
};
Expand Down Expand Up @@ -1112,10 +1111,7 @@ void from_json(const BasicJsonType& j, std::valarray<T>& l)
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name())));
}
l.resize(j.size());
for (size_t i = 0; i < j.size(); ++i)
{
l[i] = j[i];
}
std::copy(j.m_value.array->begin(), j.m_value.array->end(), std::begin(l));
}

template<typename BasicJsonType, typename CompatibleArrayType>
Expand Down

0 comments on commit 15e757c

Please sign in to comment.