summaryrefslogtreecommitdiff
path: root/TAO
diff options
context:
space:
mode:
Diffstat (limited to 'TAO')
-rw-r--r--TAO/ChangeLog13
-rw-r--r--TAO/tao/Array_Traits_T.h5
-rw-r--r--TAO/tao/Generic_Sequence_T.h88
-rw-r--r--TAO/tao/Object_Reference_Traits_T.h5
-rw-r--r--TAO/tao/String_Traits_T.h3
-rw-r--r--TAO/tao/Value_Traits_T.h3
-rw-r--r--TAO/tao/Valuetype/Valuetype_Traits_T.h3
7 files changed, 91 insertions, 29 deletions
diff --git a/TAO/ChangeLog b/TAO/ChangeLog
index c25ffc791a9..f9c2d4250f8 100644
--- a/TAO/ChangeLog
+++ b/TAO/ChangeLog
@@ -1,3 +1,16 @@
+Fri Apr 8 13:21:17 UTC 2011 Phil Mesnier <mesnier_p@ociweb.com>
+
+ * tao/Array_Traits_T.h:
+ * tao/Generic_Sequence_T.h:
+ * tao/Object_Reference_Traits_T.h:
+ * tao/String_Traits_T.h:
+ * tao/Value_Traits_T.h:
+ * tao/Valuetype/Valuetype_Traits_T.h:
+
+ Optimizations for growing unbounded sequences by changing the
+ length. Shallow copies are now used whenever possible during the
+ duplication of the existing sequence elements.
+
Thu Apr 7 11:40:00 UTC 2011 Martin Corino <mcorino@remedy.nl>
Merged changes from Remedy work branch.
diff --git a/TAO/tao/Array_Traits_T.h b/TAO/tao/Array_Traits_T.h
index 4abd34b0383..40b39edf014 100644
--- a/TAO/tao/Array_Traits_T.h
+++ b/TAO/tao/Array_Traits_T.h
@@ -82,11 +82,14 @@ struct array_traits
}
// Allow MSVC++ >= 8 checked iterators to be used.
+
+ /// @return true if shallow copy.
template <typename iter>
- inline static void copy_swap_range(
+ inline static bool copy_swap_range(
value_type * begin, value_type * end, iter dst)
{
copy_range(begin, end, dst);
+ return false;
}
};
diff --git a/TAO/tao/Generic_Sequence_T.h b/TAO/tao/Generic_Sequence_T.h
index c29dcf9ee22..bb436cb788a 100644
--- a/TAO/tao/Generic_Sequence_T.h
+++ b/TAO/tao/Generic_Sequence_T.h
@@ -1,3 +1,5 @@
+// -*- C++ -*-
+
#ifndef guard_generic_sequence_hpp
#define guard_generic_sequence_hpp
/**
@@ -143,29 +145,14 @@ public:
, buffer_(0)
, release_(false)
{
- if (rhs.maximum_ == 0 || rhs.buffer_ == 0)
- {
- maximum_ = rhs.maximum_;
- length_ = rhs.length_;
- return;
- }
- generic_sequence tmp(rhs.maximum_, rhs.length_,
- allocation_traits::allocbuf_noinit(rhs.maximum_),
- true);
- element_traits::initialize_range(
- tmp.buffer_ + tmp.length_, tmp.buffer_ + tmp.maximum_);
- element_traits::copy_range(
- rhs.buffer_,
- rhs.buffer_ + rhs.length_,
- ACE_make_checked_array_iterator (tmp.buffer_, tmp.length_));
- swap(tmp);
+ copy_internal(rhs);
}
/// Assignment operator
generic_sequence & operator=(generic_sequence const & rhs)
{
- generic_sequence tmp(rhs);
- swap(tmp);
+ copy_internal(rhs);
+
return * this;
}
@@ -199,6 +186,15 @@ public:
/// Set a new length for the sequence
void length(CORBA::ULong length)
{
+ // When sequence doesn't own a buffer it's not allowed
+ // to change it in any way.
+ if (buffer_ && !release_)
+ {
+// ACE_ERROR ((LM_ERROR,
+// ACE_TEXT ("Tried to change length of sequence when doesn't have ownership\n")));
+ return;
+ }
+
if (length <= maximum_)
{
if (buffer_ == 0)
@@ -213,7 +209,7 @@ public:
// When sequence doesn't own a buffer it's not allowed
// to change it in any way.
- if (length < length_ && release_)
+ if (length < length_ )
{
// TODO This code does not provide the strong-exception
// guarantee, but it does provide the weak-exception
@@ -238,10 +234,15 @@ public:
// destructed but *this will remain unchanged.
element_traits::initialize_range(
tmp.buffer_ + length_, tmp.buffer_ + length);
- element_traits::copy_swap_range(
- buffer_,
- buffer_ + length_,
- ACE_make_checked_array_iterator (tmp.buffer_, tmp.length_));
+ if (element_traits::copy_swap_range(
+ buffer_,
+ buffer_ + length_,
+ ACE_make_checked_array_iterator (tmp.buffer_, tmp.length_))) {
+
+ // Made a shallow copy so release buffer_ because tmp.buffer_
+ // now has the contents.
+ element_traits::zero_range(buffer_, buffer_ + length_);
+ }
swap(tmp);
}
@@ -447,6 +448,47 @@ private:
/// If true then the sequence should release the buffer when it is
/// destroyed.
mutable CORBA::Boolean release_;
+
+ /// helper method for assignment operator and copy constructor
+ /// to minimize creation of tmp sequences.
+ void copy_internal(generic_sequence const & rhs)
+ {
+ if (buffer_ == 0)
+ {
+ if (rhs.maximum_ == 0 || rhs.buffer_ == 0)
+ {
+ maximum_ = rhs.maximum_;
+ length_ = rhs.length_;
+ }
+ else
+ {
+ maximum_ = rhs.maximum_;
+ length_ = rhs.length_;
+ buffer_ = allocation_traits::allocbuf_noinit(maximum_);
+ release_ = true;
+
+ element_traits::initialize_range(
+ buffer_ + length_, buffer_ + maximum_);
+ element_traits::copy_range(
+ rhs.buffer_,
+ rhs.buffer_ + rhs.length_,
+ ACE_make_checked_array_iterator (buffer_, length_));
+ }
+ }
+ else
+ {
+ generic_sequence tmp(rhs.maximum_, rhs.length_,
+ allocation_traits::allocbuf_noinit(rhs.maximum_),
+ true);
+ element_traits::initialize_range(
+ tmp.buffer_ + tmp.length_, tmp.buffer_ + tmp.maximum_);
+ element_traits::copy_range(
+ rhs.buffer_,
+ rhs.buffer_ + rhs.length_,
+ ACE_make_checked_array_iterator (tmp.buffer_, tmp.length_));
+ swap(tmp);
+ }
+ }
};
#if defined TAO_HAS_SEQUENCE_ITERATORS && TAO_HAS_SEQUENCE_ITERATORS == 1
diff --git a/TAO/tao/Object_Reference_Traits_T.h b/TAO/tao/Object_Reference_Traits_T.h
index 08532daa8cd..826c084dc7f 100644
--- a/TAO/tao/Object_Reference_Traits_T.h
+++ b/TAO/tao/Object_Reference_Traits_T.h
@@ -53,10 +53,11 @@ struct object_reference_traits_decorator
// Allow MSVC++ >= 8 checked iterators to be used.
template <typename iter>
- inline static void copy_swap_range(
+ inline static bool copy_swap_range(
object_type ** begin, object_type ** end, iter dst)
{
- std::swap_ranges(begin, end, dst);
+ std::copy(begin, end, dst);
+ return true;
}
inline static void release_range(
diff --git a/TAO/tao/String_Traits_T.h b/TAO/tao/String_Traits_T.h
index ca1b05d990f..f4cb728cf1d 100644
--- a/TAO/tao/String_Traits_T.h
+++ b/TAO/tao/String_Traits_T.h
@@ -51,10 +51,11 @@ struct string_traits_decorator
// Allow MSVC++ >= 8 checked iterators to be used.
template <typename iter>
- inline static void copy_swap_range(
+ inline static bool copy_swap_range(
char_type ** begin, char_type ** end, iter dst)
{
std::swap_ranges(begin, end, dst);
+ return true;
}
inline static void release_range(
diff --git a/TAO/tao/Value_Traits_T.h b/TAO/tao/Value_Traits_T.h
index a36338f2b41..c991a6dfc6e 100644
--- a/TAO/tao/Value_Traits_T.h
+++ b/TAO/tao/Value_Traits_T.h
@@ -56,10 +56,11 @@ struct value_traits
// Allow MSVC++ >= 8 checked iterators to be used.
template <typename iter>
- inline static void copy_swap_range(
+ inline static bool copy_swap_range(
value_type * begin, value_type * end, iter dst)
{
copy_range(begin, end, dst);
+ return false;
}
};
diff --git a/TAO/tao/Valuetype/Valuetype_Traits_T.h b/TAO/tao/Valuetype/Valuetype_Traits_T.h
index 460ccc946ff..c096eea835a 100644
--- a/TAO/tao/Valuetype/Valuetype_Traits_T.h
+++ b/TAO/tao/Valuetype/Valuetype_Traits_T.h
@@ -52,10 +52,11 @@ struct valuetype_traits_decorator
// Allow MSVC++ >= 8 checked iterators to be used.
template <typename iter>
- inline static void copy_swap_range(
+ inline static bool copy_swap_range(
object_type ** begin, object_type ** end, iter dst)
{
std::swap_ranges(begin, end, dst);
+ return true;
}
inline static void release_range(