From a5d8483183b46642649a637d999f4798fa9bfd20 Mon Sep 17 00:00:00 2001 From: Hugo Santos Date: Thu, 5 Apr 2007 20:45:10 +0000 Subject: [PATCH] small cleanup, use get_node_at_offset(). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20591 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/network/stack/net_buffer.cpp | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/add-ons/kernel/network/stack/net_buffer.cpp b/src/add-ons/kernel/network/stack/net_buffer.cpp index a870b603ec..b1b8c366a6 100644 --- a/src/add-ons/kernel/network/stack/net_buffer.cpp +++ b/src/add-ons/kernel/network/stack/net_buffer.cpp @@ -240,6 +240,20 @@ remove_data_node(data_node *node) } +static inline data_node * +get_node_at_offset(net_buffer_private *buffer, size_t offset) +{ + data_node *node = (data_node *)list_get_first_item(&buffer->buffers); + while (node->offset + node->used < offset) { + node = (data_node *)list_get_next_item(&buffer->buffers, node); + if (node == NULL) + return NULL; + } + + return node; +} + + // #pragma mark - @@ -528,19 +542,6 @@ merge_buffer(net_buffer *_buffer, net_buffer *_with, bool after) } -static inline data_node * -get_node_at_offset(net_buffer_private *buffer, size_t offset) -{ - data_node *node = (data_node *)list_get_first_item(&buffer->buffers); - while (node->offset + node->used < offset) { - node = (data_node *)list_get_next_item(&buffer->buffers, node); - if (node == NULL) - return NULL; - } - - return node; -} - /*! Writes into existing allocated memory. \return B_BAD_VALUE if you write outside of the buffers current bounds. @@ -870,13 +871,10 @@ trim_data(net_buffer *_buffer, size_t newSize) if (newSize == buffer->size) return B_OK; - data_node *node = (data_node *)list_get_first_item(&buffer->buffers); - while (node->offset + node->used < newSize) { - node = (data_node *)list_get_next_item(&buffer->buffers, node); - if (node == NULL) { - // trim size greater than buffer size - return B_BAD_VALUE; - } + data_node *node = get_node_at_offset(buffer, newSize); + if (node == NULL) { + // trim size greater than buffer size + return B_BAD_VALUE; } int32 diff = node->used + node->offset - newSize;