From 0e4f7f0dc545498484bae7da7a1a177107dbdb2c Mon Sep 17 00:00:00 2001 From: schmidt Date: Tue, 6 May 1997 17:44:29 +0000 Subject: *** empty log message *** --- ace/Containers.cpp | 60 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 21 deletions(-) (limited to 'ace/Containers.cpp') diff --git a/ace/Containers.cpp b/ace/Containers.cpp index b8dce3c7546..005138df79e 100644 --- a/ace/Containers.cpp +++ b/ace/Containers.cpp @@ -347,7 +347,7 @@ ACE_Unbounded_Queue::enqueue_head (const T &new_item) ACE_Node *temp; // Create a new node that points to the original head. - ACE_NEW_RETURN (temp, ACE_Node (new_item, this->head_->next_->next_), -1); + ACE_NEW_RETURN (temp, ACE_Node (new_item, this->head_->next_), -1); // Link this pointer into the front of the list. this->head_->next_ = temp; @@ -439,28 +439,43 @@ ACE_Unbounded_Queue::set (const T &item, ACE_Node *curr = this->head_->next_; - int result = 1; size_t i; - for (i = 0; i <= index; i++) - { - if (i == this->cur_size_) - { - // We need to expand the list. + for (i = 0; + i < index && i < this->cur_size_; + i++) + curr = curr->next_; - result = 0; + if (i < this->cur_size_) + { + // We're in range, so everything's cool. + curr->item_ = item; + return 1; + } + else + { + // We need to expand the list. - // A common case will be increasing the set size by 1. - // Therefore, we'll optimize for this case. - if (i + i == index) - // Try to expand the size of the set by 1. - return this->enqueue_tail (item); + // A common case will be increasing the set size by 1. + // Therefore, we'll optimize for this case. + if (i == index) + { + // Try to expand the size of the set by 1. + if (this->enqueue_tail (item) == -1) + return -1; else - { - T dummy; + return 0; + } + else + { + T dummy; + // We need to expand the list by multiple (dummy) items. + for (; i < index; i++) + { // This head points to the existing dummy node, which is - // about to be overwritten when we add the new dummy node. + // about to be overwritten when we add the new dummy + // node. curr = this->head_; // Try to expand the size of the set by 1, but don't @@ -468,13 +483,11 @@ ACE_Unbounded_Queue::set (const T &item, if (this->enqueue_tail (dummy) == -1) return -1; } + + curr->item_ = item; + return 0; } - else - curr = curr->next_; } - - curr->item_ = item; - return result; } template void @@ -935,6 +948,11 @@ ACE_Bounded_Set_Iterator::next (T *&item) ACE_ALLOC_HOOK_DEFINE(ACE_Node) +template +ACE_Node::~ACE_Node (void) +{ +} + template ACE_Node::ACE_Node (const T &i, ACE_Node *n) : next_ (n), -- cgit v1.2.1