Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends
nsScannerBufferList Class Reference

nsScannerBufferList More...

#include <nsScannerString.h>

List of all members.

Classes

class  Buffer
 Buffer objects are directly followed by a data segment. More...
class  Position
 Position objects serve as lightweight pointers into a buffer list. More...

Public Member Functions

 nsScannerBufferList (Buffer *buf)
void AddRef ()
void Release ()
void Append (Buffer *buf)
void InsertAfter (Buffer *buf, Buffer *prev)
void SplitBuffer (const Position &)
void DiscardUnreferencedPrefix (Buffer *)
BufferHead ()
const BufferHead () const
BufferTail ()
const BufferTail () const

Static Public Member Functions

static BufferAllocBufferFromString (const nsAString &)
 nsScannerBufferList
static BufferAllocBuffer (PRUint32 capacity)

Private Member Functions

 ~nsScannerBufferList ()
void ReleaseAll ()

Private Attributes

PRInt32 mRefCnt
PRCList mBuffers

Friends

class nsScannerSubstring

Detailed Description

nsScannerBufferList

This class maintains a list of heap-allocated Buffer objects. The buffers are maintained in a circular linked list. Each buffer has a usage count that is decremented by the owning nsScannerSubstring.

The buffer list itself is reference counted. This allows the buffer list to be shared by multiple nsScannerSubstring objects. The reference counting is not threadsafe, which is not at all a requirement.

When a nsScannerSubstring releases its reference to a buffer list, it decrements the usage count of the first buffer in the buffer list that it was referencing. It informs the buffer list that it can discard buffers starting at that prefix. The buffer list will do so if the usage count of that buffer is 0 and if it is the first buffer in the list. It will continue to prune buffers starting from the front of the buffer list until it finds a buffer that has a usage count that is non-zero.

Definition at line 86 of file nsScannerString.h.


Constructor & Destructor Documentation

Definition at line 158 of file nsScannerString.h.

Definition at line 183 of file nsScannerString.h.

{ ReleaseAll(); }

Here is the call graph for this function:


Member Function Documentation

Definition at line 165 of file nsScannerString.h.

{ ++mRefCnt; }

Here is the caller graph for this function:

Definition at line 72 of file nsScannerString.cpp.

  {
    Buffer* buf = (Buffer*) malloc(sizeof(Buffer) + (capacity + 1) * sizeof(PRUnichar));
    if (buf)
      {
        // leave PRCList members of Buffer uninitialized

        buf->mUsageCount = 0;
        buf->mDataEnd = buf->DataStart() + capacity;

        // XXX null terminate.  this shouldn't be required, but we do it because
        // nsScanner erroneously thinks it can dereference DataEnd :-(
        *buf->mDataEnd = PRUnichar(0);
      }
    return buf;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

nsScannerBufferList

Definition at line 48 of file nsScannerString.cpp.

  {
    PRUint32 len = aString.Length();

    Buffer* buf = (Buffer*) malloc(sizeof(Buffer) + (len + 1) * sizeof(PRUnichar));
    if (buf)
      {
        // leave PRCList members of Buffer uninitialized

        buf->mUsageCount = 0;
        buf->mDataEnd = buf->DataStart() + len;

        nsAString::const_iterator source;
        aString.BeginReading(source);
        nsCharTraits<PRUnichar>::copy(buf->DataStart(), source.get(), len);

        // XXX null terminate.  this shouldn't be required, but we do it because
        // nsScanner erroneously thinks it can dereference DataEnd :-(
        *buf->mDataEnd = PRUnichar(0);
      }
    return buf;
  }

Here is the call graph for this function:

Definition at line 168 of file nsScannerString.h.

Here is the caller graph for this function:

Definition at line 128 of file nsScannerString.cpp.

  {
    if (aBuf == Head())
      {
        while (!PR_CLIST_IS_EMPTY(&mBuffers) && !Head()->IsInUse())
          {
            Buffer* buffer = Head();
            PR_REMOVE_LINK(buffer);
            free(buffer);
          }
      }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 173 of file nsScannerString.h.

{ return NS_STATIC_CAST(      Buffer*, PR_LIST_HEAD(&mBuffers)); }

Here is the caller graph for this function:

const Buffer* nsScannerBufferList::Head ( ) const [inline]

Definition at line 174 of file nsScannerString.h.

{ return NS_STATIC_CAST(const Buffer*, PR_LIST_HEAD(&mBuffers)); }
void nsScannerBufferList::InsertAfter ( Buffer buf,
Buffer prev 
) [inline]

Definition at line 169 of file nsScannerString.h.

{ PR_INSERT_AFTER(buf, prev); }

Here is the caller graph for this function:

Definition at line 166 of file nsScannerString.h.

{ if (--mRefCnt == 0) delete this; }

Here is the caller graph for this function:

Definition at line 90 of file nsScannerString.cpp.

  {
    while (!PR_CLIST_IS_EMPTY(&mBuffers))
      {
        PRCList* node = PR_LIST_HEAD(&mBuffers);
        PR_REMOVE_LINK(node);
        //printf(">>> freeing buffer @%p\n", node);
        free(NS_STATIC_CAST(Buffer*, node));
      }
  }

Here is the caller graph for this function:

Definition at line 102 of file nsScannerString.cpp.

  {
    // splitting to the right keeps the work string and any extant token
    // pointing to and holding a reference count on the same buffer.

    Buffer* bufferToSplit = pos.mBuffer;
    NS_ASSERTION(bufferToSplit, "null pointer");

    PRUint32 splitOffset = pos.mPosition - bufferToSplit->DataStart();
    NS_ASSERTION(pos.mPosition >= bufferToSplit->DataStart() &&
                 splitOffset <= bufferToSplit->DataLength(),
                 "split offset is outside buffer");
    
    PRUint32 len = bufferToSplit->DataLength() - splitOffset;
    Buffer* new_buffer = AllocBuffer(len);
    if (new_buffer)
      {
        nsCharTraits<PRUnichar>::copy(new_buffer->DataStart(),
                                      bufferToSplit->DataStart() + splitOffset,
                                      len);
        InsertAfter(new_buffer, bufferToSplit);
        bufferToSplit->SetDataLength(splitOffset);
      }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 176 of file nsScannerString.h.

{ return NS_STATIC_CAST(      Buffer*, PR_LIST_TAIL(&mBuffers)); }

Here is the caller graph for this function:

const Buffer* nsScannerBufferList::Tail ( ) const [inline]

Definition at line 177 of file nsScannerString.h.

{ return NS_STATIC_CAST(const Buffer*, PR_LIST_TAIL(&mBuffers)); }

Friends And Related Function Documentation

friend class nsScannerSubstring [friend]

Definition at line 181 of file nsScannerString.h.


Member Data Documentation

PRCList nsScannerBufferList::mBuffers [private]

Definition at line 187 of file nsScannerString.h.

Definition at line 186 of file nsScannerString.h.


The documentation for this class was generated from the following files: