Don't try to do a 'fast path' by checking RB_MAX. RB_MAX walks the
tree which means it can be quite expensive. This cost would be paid
for virtually every data segment. The actual insert that follows would
walk the tree again.
Instead, simply insert it. There is a slight cost of the unnecessary
overlap check, but this is much less than the tree walk in a full
tree.
return 0;
}
- /* insert the segment in the stream tree using this fast track, if seg->seq
- is equal or higher than last segments tail. */
- TcpSegment *last = RB_MAX(TCPSEG, &stream->seg_tree);
- if (last && SEQ_GEQ(seg->seq, (uint32_t)SEG_SEQ_RIGHT_EDGE(last)))
- {
- SCLogDebug("seg beyond tree tail, append");
- TCPSEG_RB_INSERT(&stream->seg_tree, seg);
- return 0;
- }
-
/* insert and then check if there was any overlap with other segments */
TcpSegment *res = TCPSEG_RB_INSERT(&stream->seg_tree, seg);
if (res) {