Improved performance of emplace for value_type parameters

This commit is contained in:
John Wellbelove 2018-02-04 14:52:31 +00:00
parent d93e60f273
commit c43adc7df3
6 changed files with 13 additions and 70 deletions

View File

@ -1,5 +1,5 @@
name=Embedded Template Library
version=10.16.0
version=10.16.1
author= John Wellbelove <john.wellbelove@etlcpp.com>
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
sentence=A C++ template library tailored for embedded systems.

View File

@ -341,29 +341,7 @@ namespace etl
//*************************************************************************
std::pair<iterator, bool> emplace(const value_type& value)
{
ETL_ASSERT(!full(), ETL_ERROR(flat_map_full));
// Create it.
value_type* pvalue = storage.allocate<value_type>();
::new (pvalue) value_type(value);
iterator i_element = lower_bound(value.first);
std::pair<iterator, bool> result(i_element, false);
// Doesn't already exist?
if ((i_element == end() || (i_element->first != value.first)))
{
++construct_count;
result = refmap_t::insert_at(i_element, *pvalue);
}
else
{
pvalue->~value_type();
storage.release(pvalue);
}
return result;
return insert(value);
}
//*************************************************************************
@ -375,7 +353,8 @@ namespace etl
// Create it.
value_type* pvalue = storage.allocate<value_type>();
::new (pvalue) value_type(key, value);
::new ((void*)etl::addressof(pvalue->first)) key_type(key);
::new ((void*)etl::addressof(pvalue->second)) mapped_type(value);
iterator i_element = lower_bound(key);

View File

@ -294,15 +294,7 @@ namespace etl
//*************************************************************************
std::pair<iterator, bool> emplace(const value_type& value)
{
ETL_ASSERT(!full(), ETL_ERROR(flat_multimap_full));
// Create it.
value_type* pvalue = storage.allocate<value_type>();
::new (pvalue) value_type(value);
iterator i_element = lower_bound(value.first);
++construct_count;
return refmap_t::insert_at(i_element, *pvalue);
return insert(value);
}
//*************************************************************************
@ -314,7 +306,8 @@ namespace etl
// Create it.
value_type* pvalue = storage.allocate<value_type>();
::new (pvalue) value_type(key, value);
::new ((void*)etl::addressof(pvalue->first)) key_type(key);
::new ((void*)etl::addressof(pvalue->second)) mapped_type(value);
iterator i_element = lower_bound(key);
++construct_count;

View File

@ -271,16 +271,7 @@ namespace etl
template <typename T1>
std::pair<iterator, bool> emplace(parameter_t value)
{
ETL_ASSERT(!full(), ETL_ERROR(flat_multiset_full));
// Create it.
value_type* pvalue = storage.allocate<value_type>();
::new (pvalue) value_type(value);
iterator i_element = lower_bound(*pvalue);
++construct_count;
return std::pair<iterator, bool>(refset_t::insert_at(i_element, *pvalue));
return insert(value);
}
//*************************************************************************

View File

@ -274,31 +274,7 @@ namespace etl
//*************************************************************************
std::pair<iterator, bool> emplace(parameter_t value)
{
ETL_ASSERT(!full(), ETL_ERROR(flat_set_full));
std::pair<iterator, bool> result;
// Create it.
value_type* pvalue = storage.allocate<value_type>();
::new (pvalue) value_type(value);
iterator i_element = lower_bound(*pvalue);
// Doesn't already exist?
if ((i_element == end() || (*i_element != *pvalue)))
{
++construct_count;
result = refset_t::insert_at(i_element, *pvalue);
}
else
{
// Destroy it.
pvalue->~value_type();
storage.release(pvalue);
result = std::pair<iterator, bool>(end(), false);
}
return result;
return insert(value);
}
//*************************************************************************

View File

@ -1,3 +1,7 @@
===============================================================================
10.16.1
Improved performance of emplace for value_type parameters.
===============================================================================
10.16.0
Added emplace member functions to flat_map, flat_multimap, flat_set and flat_multiset