auto queue node size
parent
ace4054444
commit
da759fb13a
15
queue.cpp
15
queue.cpp
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
NAMESPACE_BEGIN(CryptoPP)
|
NAMESPACE_BEGIN(CryptoPP)
|
||||||
|
|
||||||
|
static const unsigned int s_maxAutoNodeSize = 16*1024;
|
||||||
|
|
||||||
// this class for use by ByteQueue only
|
// this class for use by ByteQueue only
|
||||||
class ByteQueueNode
|
class ByteQueueNode
|
||||||
{
|
{
|
||||||
|
|
@ -123,8 +125,8 @@ public:
|
||||||
|
|
||||||
// ********************************************************
|
// ********************************************************
|
||||||
|
|
||||||
ByteQueue::ByteQueue(unsigned int m_nodeSize)
|
ByteQueue::ByteQueue(unsigned int nodeSize)
|
||||||
: m_nodeSize(m_nodeSize), m_lazyLength(0)
|
: m_autoNodeSize(m_nodeSize==0), m_nodeSize(nodeSize ? nodeSize : 256), m_lazyLength(0)
|
||||||
{
|
{
|
||||||
m_head = m_tail = new ByteQueueNode(m_nodeSize);
|
m_head = m_tail = new ByteQueueNode(m_nodeSize);
|
||||||
}
|
}
|
||||||
|
|
@ -137,6 +139,7 @@ ByteQueue::ByteQueue(const ByteQueue ©)
|
||||||
void ByteQueue::CopyFrom(const ByteQueue ©)
|
void ByteQueue::CopyFrom(const ByteQueue ©)
|
||||||
{
|
{
|
||||||
m_lazyLength = 0;
|
m_lazyLength = 0;
|
||||||
|
m_autoNodeSize = copy.m_autoNodeSize;
|
||||||
m_nodeSize = copy.m_nodeSize;
|
m_nodeSize = copy.m_nodeSize;
|
||||||
m_head = m_tail = new ByteQueueNode(*copy.m_head);
|
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;
|
inString += len;
|
||||||
length -= 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;
|
m_tail = m_tail->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
3
queue.h
3
queue.h
|
|
@ -16,7 +16,7 @@ class ByteQueueNode;
|
||||||
class ByteQueue : public Bufferless<BufferedTransformation>
|
class ByteQueue : public Bufferless<BufferedTransformation>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ByteQueue(unsigned int m_nodeSize=256);
|
ByteQueue(unsigned int m_nodeSize=0);
|
||||||
ByteQueue(const ByteQueue ©);
|
ByteQueue(const ByteQueue ©);
|
||||||
~ByteQueue();
|
~ByteQueue();
|
||||||
|
|
||||||
|
|
@ -99,6 +99,7 @@ private:
|
||||||
void CopyFrom(const ByteQueue ©);
|
void CopyFrom(const ByteQueue ©);
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
|
bool m_autoNodeSize;
|
||||||
unsigned int m_nodeSize;
|
unsigned int m_nodeSize;
|
||||||
ByteQueueNode *m_head, *m_tail;
|
ByteQueueNode *m_head, *m_tail;
|
||||||
byte *m_lazyString;
|
byte *m_lazyString;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue