diff options
author | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2003-06-20 03:12:54 +0000 |
---|---|---|
committer | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2003-06-20 03:12:54 +0000 |
commit | 32fdd18f7efa899c582f4c6eaa92d304d5fe0fd4 (patch) | |
tree | 153a0d9ffdbeff5955688bd6fd08bc91cab539f0 /queue.cpp | |
parent | 91f4f6d49ab4d82046b36776c584545800f4d1f4 (diff) | |
download | cryptopp-32fdd18f7efa899c582f4c6eaa92d304d5fe0fd4.tar.gz |
auto queue node size
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@84 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'queue.cpp')
-rw-r--r-- | queue.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -6,6 +6,8 @@ NAMESPACE_BEGIN(CryptoPP) +static const unsigned int s_maxAutoNodeSize = 16*1024; + // this class for use by ByteQueue only class ByteQueueNode { @@ -123,8 +125,8 @@ public: // ******************************************************** -ByteQueue::ByteQueue(unsigned int m_nodeSize) - : m_nodeSize(m_nodeSize), m_lazyLength(0) +ByteQueue::ByteQueue(unsigned int nodeSize) + : m_autoNodeSize(m_nodeSize==0), m_nodeSize(nodeSize ? nodeSize : 256), m_lazyLength(0) { m_head = m_tail = new ByteQueueNode(m_nodeSize); } @@ -137,6 +139,7 @@ ByteQueue::ByteQueue(const ByteQueue ©) void ByteQueue::CopyFrom(const ByteQueue ©) { m_lazyLength = 0; + m_autoNodeSize = copy.m_autoNodeSize; m_nodeSize = copy.m_nodeSize; m_head = m_tail = new ByteQueueNode(*copy.m_head); @@ -210,7 +213,13 @@ unsigned int ByteQueue::Put2(const byte *inString, unsigned int length, int mess { inString += len; length -= len; - m_tail->next = new ByteQueueNode(STDMAX(m_nodeSize, STDMIN(length, 16U*1024U))); + if (m_autoNodeSize && m_nodeSize < s_maxAutoNodeSize) + do + { + m_nodeSize *= 2; + } + while (m_nodeSize < length && m_nodeSize < s_maxAutoNodeSize); + m_tail->next = new ByteQueueNode(STDMAX(m_nodeSize, length)); m_tail = m_tail->next; } |