libcsdbg  1.28
C++ exception (and generic) stack trace debug library
template<class T >
node< T > * csdbg::chain< T >::detach_node ( u32  i)
protectedvirtual

Detach the node at a chain offset.

Parameters
[in]ithe offset
Returns
the detached i-th node
Exceptions
csdbg::exception

Definition at line 167 of file chain.hpp.

References likely, csdbg::node< T >::link(), csdbg::node< T >::link_to(), unlikely, and csdbg::node< T >::unlink_from().

168 {
169  if ( unlikely(i >= m_size) )
170  throw exception("offset out of chain bounds (%d >= %d)", i, m_size);
171 
172  node<T> *cur = m_head, *prev = NULL, *next;
173  while ( likely(i-- > 0) ) {
174  next = cur->link(prev);
175  prev = cur;
176  cur = next;
177  }
178 
179  next = cur->link(prev);
180 
181  /* If it's the first in the chain */
182  if ( unlikely(cur == m_head) ) {
183  m_head = next;
184 
185  /* If the chain is left empty */
186  if ( unlikely(m_head == NULL) )
187  m_tail = NULL;
188  else
189  m_head->unlink_from(cur);
190  }
191 
192  /* If it's the last in the chain */
193  else if ( unlikely(cur == m_tail) ) {
194  m_tail = prev;
195  m_tail->unlink_from(cur);
196  }
197 
198  /* Relink previous and next nodes */
199  else {
200  prev->unlink_from(cur);
201  prev->link_to(next);
202 
203  next->unlink_from(cur);
204  next->link_to(prev);
205  }
206 
207  m_size--;
208  return cur;
209 }
u32 m_size
Node count.
Definition: chain.hpp:43
#define likely(expr)
Offer a hint (positive) to the pipeline branch predictor.
Definition: config.hpp:344
node< T > * m_tail
Chain tail.
Definition: chain.hpp:41
node< T > * m_head
Chain head.
Definition: chain.hpp:39
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
Definition: config.hpp:349

+ Here is the call graph for this function: