Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
nsContentList.cpp File Reference
#include "nsContentList.h"
#include "nsIContent.h"
#include "nsIDOMNode.h"
#include "nsIDOM3Node.h"
#include "nsIDocument.h"
#include "nsGenericElement.h"
#include "nsContentUtils.h"
#include "nsLayoutAtoms.h"
#include "nsHTMLAtoms.h"
#include "nsIDOMHTMLFormElement.h"
#include "pldhash.h"

Go to the source code of this file.

Classes

struct  ContentListHashEntry

Functions

 ContentListHashtableGetKey (PLDHashTable *table, PLDHashEntryHdr *entry)
 ContentListHashtableHashKey (PLDHashTable *table, const void *key)
 ContentListHashtableMatchEntry (PLDHashTable *table, const PLDHashEntryHdr *entry, const void *key)
already_AddRefed< nsContentListNS_GetContentList (nsIDocument *aDocument, nsIAtom *aMatchAtom, PRInt32 aMatchNameSpaceId, nsIContent *aRootContent)

Variables

static nsContentListgCachedContentList
static PLDHashTable gContentListHashTable

Function Documentation

Definition at line 167 of file nsContentList.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 174 of file nsContentList.cpp.

{
  const nsContentListKey* list = NS_STATIC_CAST(const nsContentListKey *, key);
  return list->GetHash();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 181 of file nsContentList.cpp.

{
  const ContentListHashEntry *e =
    NS_STATIC_CAST(const ContentListHashEntry *, entry);
  const nsContentListKey* list1 = e->mContentList->GetKey();
  const nsContentListKey* list2 = NS_STATIC_CAST(const nsContentListKey *, key);

  return list1->Equals(*list2);
}

Here is the call graph for this function:

Here is the caller graph for this function:

already_AddRefed<nsContentList> NS_GetContentList ( nsIDocument aDocument,
nsIAtom aMatchAtom,
PRInt32  aMatchNameSpaceId,
nsIContent aRootContent 
)

Definition at line 194 of file nsContentList.cpp.

{
  nsContentList* list = nsnull;

  static PLDHashTableOps hash_table_ops =
  {
    PL_DHashAllocTable,
    PL_DHashFreeTable,
    ContentListHashtableGetKey,
    ContentListHashtableHashKey,
    ContentListHashtableMatchEntry,
    PL_DHashMoveEntryStub,
    PL_DHashClearEntryStub,
    PL_DHashFinalizeStub
  };

  // Initialize the hashtable if needed.
  if (!gContentListHashTable.ops) {
    PRBool success = PL_DHashTableInit(&gContentListHashTable,
                                       &hash_table_ops, nsnull,
                                       sizeof(ContentListHashEntry),
                                       16);

    if (!success) {
      gContentListHashTable.ops = nsnull;
    }
  }
  
  ContentListHashEntry *entry = nsnull;
  // First we look in our hashtable.  Then we create a content list if needed
  if (gContentListHashTable.ops) {
    nsContentListKey hashKey(aDocument, aMatchAtom,
                             aMatchNameSpaceId, aRootContent);
    
    // A PL_DHASH_ADD is equivalent to a PL_DHASH_LOOKUP for cases
    // when the entry is already in the hashtable.
    entry = NS_STATIC_CAST(ContentListHashEntry *,
                           PL_DHashTableOperate(&gContentListHashTable,
                                                &hashKey,
                                                PL_DHASH_ADD));
    if (entry)
      list = entry->mContentList;
  }

  if (!list) {
    // We need to create a ContentList and add it to our new entry, if
    // we have an entry
    list = new nsContentList(aDocument, aMatchAtom,
                             aMatchNameSpaceId, aRootContent);
    if (entry) {
      if (list)
        entry->mContentList = list;
      else
        PL_DHashTableRawRemove(&gContentListHashTable, entry);
    }

    NS_ENSURE_TRUE(list, nsnull);
  }

  NS_ADDREF(list);

  // Hold on to the last requested content list to avoid having it be
  // removed from the cache immediately when it's released. Avoid
  // bumping the refcount on the list if the requested list is the one
  // that's already cached.

  if (!aRootContent && gCachedContentList != list) {
    NS_IF_RELEASE(gCachedContentList);

    gCachedContentList = list;
    NS_ADDREF(gCachedContentList);
  }

  return list;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 56 of file nsContentList.cpp.

Definition at line 159 of file nsContentList.cpp.