diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 238aca10..6cb44280 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -259,19 +259,16 @@ namespace etl //************************************************************************* bool contains_node(const link_type& search_link) const { - const link_type* p_link = start.etl_next; + return is_link_in_list(&search_link); + } - while (p_link != ETL_NULLPTR) - { - if (&search_link == p_link) - { - return true; - } - - p_link = p_link->link_type::etl_next; - } - - return false; + //************************************************************************* + /// Detects existence of specified node in list. + ///\param search_link The node to find in list + //************************************************************************* + bool contains_node(const link_type* search_link) const + { + return is_link_in_list(search_link); } protected: @@ -359,10 +356,10 @@ namespace etl /// Tests if the link is in this list. /// Returns the previous link to it, if found, otherwise ETL_NULLPTR. //************************************************************************* - link_type* is_link_in_list(const link_type* search_link) + link_type* is_link_in_list(const link_type* search_link) const { link_type* p_link = start.etl_next; - link_type* p_previous = &start; + link_type* p_previous = const_cast(&start); while (p_link != ETL_NULLPTR) { diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index 673852c1..563fadfa 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -259,21 +259,18 @@ namespace etl /// Detects existence of specified node in list. ///\param search_link The node to find in list //************************************************************************* - bool contains_node(link_type& search_link) const + bool contains_node(const link_type& search_link) const { - link_type* p_link = terminal_link.link_type::etl_next; + return is_link_in_list(&search_link);; + } - while (p_link != &terminal_link) - { - if (&search_link == p_link) - { - return true; - } - - p_link = p_link->link_type::etl_next; - } - - return false; + //************************************************************************* + /// Detects existence of specified node in list. + ///\param search_link The node to find in list + //************************************************************************* + bool contains_node(const link_type* search_link) const + { + return is_link_in_list(search_link);; } protected: @@ -425,7 +422,7 @@ namespace etl { link_type* result = ETL_NULLPTR; - if (contains_node(link)) + if (is_link_in_list(link)) { link_type* p_next = link->etl_next;