Skip to content

Commit 6124367

Browse files
author
John Wellbelove
committed
Integration of contains and contains_node
1 parent 12743be commit 6124367

File tree

2 files changed

+22
-28
lines changed

2 files changed

+22
-28
lines changed

include/etl/intrusive_forward_list.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -259,19 +259,16 @@ namespace etl
259259
//*************************************************************************
260260
bool contains_node(const link_type& search_link) const
261261
{
262-
const link_type* p_link = start.etl_next;
263-
264-
while (p_link != ETL_NULLPTR)
265-
{
266-
if (&search_link == p_link)
267-
{
268-
return true;
269-
}
270-
271-
p_link = p_link->link_type::etl_next;
272-
}
262+
return is_link_in_list(&search_link);
263+
}
273264

274-
return false;
265+
//*************************************************************************
266+
/// Detects existence of specified node in list.
267+
///\param search_link The node to find in list
268+
//*************************************************************************
269+
bool contains_node(const link_type* search_link) const
270+
{
271+
return is_link_in_list(search_link);
275272
}
276273

277274
protected:
@@ -359,10 +356,10 @@ namespace etl
359356
/// Tests if the link is in this list.
360357
/// Returns the previous link to it, if found, otherwise ETL_NULLPTR.
361358
//*************************************************************************
362-
link_type* is_link_in_list(const link_type* search_link)
359+
link_type* is_link_in_list(const link_type* search_link) const
363360
{
364361
link_type* p_link = start.etl_next;
365-
link_type* p_previous = &start;
362+
link_type* p_previous = const_cast<link_type*>(&start);
366363

367364
while (p_link != ETL_NULLPTR)
368365
{

include/etl/intrusive_list.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -259,21 +259,18 @@ namespace etl
259259
/// Detects existence of specified node in list.
260260
///\param search_link The node to find in list
261261
//*************************************************************************
262-
bool contains_node(link_type& search_link) const
262+
bool contains_node(const link_type& search_link) const
263263
{
264-
link_type* p_link = terminal_link.link_type::etl_next;
265-
266-
while (p_link != &terminal_link)
267-
{
268-
if (&search_link == p_link)
269-
{
270-
return true;
271-
}
272-
273-
p_link = p_link->link_type::etl_next;
274-
}
264+
return is_link_in_list(&search_link);;
265+
}
275266

276-
return false;
267+
//*************************************************************************
268+
/// Detects existence of specified node in list.
269+
///\param search_link The node to find in list
270+
//*************************************************************************
271+
bool contains_node(const link_type* search_link) const
272+
{
273+
return is_link_in_list(search_link);;
277274
}
278275

279276
protected:
@@ -425,7 +422,7 @@ namespace etl
425422
{
426423
link_type* result = ETL_NULLPTR;
427424

428-
if (contains_node(link))
425+
if (is_link_in_list(link))
429426
{
430427
link_type* p_next = link->etl_next;
431428

0 commit comments

Comments
 (0)