Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit ccee1b5

Browse files
committed
Bug 1165768 (part 5) - Convert |gEntityToUnicode| and |gUnicodeToEntity| to |PLDHashTable2*|. r=froydnj.
--HG-- extra : rebase_source : 06a8ba73fdab7f8ff0c2a7813daa1f55d76e0b54
1 parent ee79b4a commit ccee1b5

1 file changed

Lines changed: 21 additions & 25 deletions

File tree

parser/htmlparser/nsHTMLEntities.cpp

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
#include "nsHTMLEntities.h"
99

10-
11-
1210
#include "nsString.h"
1311
#include "nsCRT.h"
1412
#include "pldhash.h"
@@ -67,8 +65,8 @@ static const PLDHashTableOps UnicodeToEntityOps = {
6765
nullptr,
6866
};
6967

70-
static PLDHashTable gEntityToUnicode;
71-
static PLDHashTable gUnicodeToEntity;
68+
static PLDHashTable2* gEntityToUnicode;
69+
static PLDHashTable2* gUnicodeToEntity;
7270
static nsrefcnt gTableRefCnt = 0;
7371

7472
#define HTML_ENTITY(_name, _value) { #_name, _value },
@@ -83,26 +81,28 @@ nsresult
8381
nsHTMLEntities::AddRefTable(void)
8482
{
8583
if (!gTableRefCnt) {
86-
PL_DHashTableInit(&gEntityToUnicode, &EntityToUnicodeOps,
87-
sizeof(EntityNodeEntry), NS_HTML_ENTITY_COUNT);
88-
PL_DHashTableInit(&gUnicodeToEntity, &UnicodeToEntityOps,
89-
sizeof(EntityNodeEntry), NS_HTML_ENTITY_COUNT);
84+
gEntityToUnicode = new PLDHashTable2(&EntityToUnicodeOps,
85+
sizeof(EntityNodeEntry),
86+
NS_HTML_ENTITY_COUNT);
87+
gUnicodeToEntity = new PLDHashTable2(&UnicodeToEntityOps,
88+
sizeof(EntityNodeEntry),
89+
NS_HTML_ENTITY_COUNT);
9090
for (const EntityNode *node = gEntityArray,
9191
*node_end = ArrayEnd(gEntityArray);
9292
node < node_end; ++node) {
9393

9494
// add to Entity->Unicode table
9595
EntityNodeEntry* entry =
9696
static_cast<EntityNodeEntry*>
97-
(PL_DHashTableAdd(&gEntityToUnicode, node->mStr, fallible));
97+
(PL_DHashTableAdd(gEntityToUnicode, node->mStr, fallible));
9898
NS_ASSERTION(entry, "Error adding an entry");
9999
// Prefer earlier entries when we have duplication.
100100
if (!entry->node)
101101
entry->node = node;
102102

103103
// add to Unicode->Entity table
104104
entry = static_cast<EntityNodeEntry*>
105-
(PL_DHashTableAdd(&gUnicodeToEntity,
105+
(PL_DHashTableAdd(gUnicodeToEntity,
106106
NS_INT32_TO_PTR(node->mUnicode),
107107
fallible));
108108
NS_ASSERTION(entry, "Error adding an entry");
@@ -111,8 +111,8 @@ nsHTMLEntities::AddRefTable(void)
111111
entry->node = node;
112112
}
113113
#ifdef DEBUG
114-
PL_DHashMarkTableImmutable(&gUnicodeToEntity);
115-
PL_DHashMarkTableImmutable(&gEntityToUnicode);
114+
PL_DHashMarkTableImmutable(gUnicodeToEntity);
115+
PL_DHashMarkTableImmutable(gEntityToUnicode);
116116
#endif
117117
}
118118
++gTableRefCnt;
@@ -125,20 +125,17 @@ nsHTMLEntities::ReleaseTable(void)
125125
if (--gTableRefCnt != 0)
126126
return;
127127

128-
if (gEntityToUnicode.IsInitialized()) {
129-
PL_DHashTableFinish(&gEntityToUnicode);
130-
}
131-
if (gUnicodeToEntity.IsInitialized()) {
132-
PL_DHashTableFinish(&gUnicodeToEntity);
133-
}
128+
delete gEntityToUnicode;
129+
delete gUnicodeToEntity;
130+
gEntityToUnicode = nullptr;
131+
gUnicodeToEntity = nullptr;
134132
}
135133

136134
int32_t
137135
nsHTMLEntities::EntityToUnicode(const nsCString& aEntity)
138136
{
139-
NS_ASSERTION(gEntityToUnicode.IsInitialized(),
140-
"no lookup table, needs addref");
141-
if (!gEntityToUnicode.IsInitialized())
137+
NS_ASSERTION(gEntityToUnicode, "no lookup table, needs addref");
138+
if (!gEntityToUnicode)
142139
return -1;
143140

144141
//this little piece of code exists because entities may or may not have the terminating ';'.
@@ -152,7 +149,7 @@ nsHTMLEntities::EntityToUnicode(const nsCString& aEntity)
152149

153150
EntityNodeEntry* entry =
154151
static_cast<EntityNodeEntry*>
155-
(PL_DHashTableSearch(&gEntityToUnicode, aEntity.get()));
152+
(PL_DHashTableSearch(gEntityToUnicode, aEntity.get()));
156153

157154
return entry ? entry->node->mUnicode : -1;
158155
}
@@ -172,11 +169,10 @@ nsHTMLEntities::EntityToUnicode(const nsAString& aEntity) {
172169
const char*
173170
nsHTMLEntities::UnicodeToEntity(int32_t aUnicode)
174171
{
175-
NS_ASSERTION(gUnicodeToEntity.IsInitialized(),
176-
"no lookup table, needs addref");
172+
NS_ASSERTION(gUnicodeToEntity, "no lookup table, needs addref");
177173
EntityNodeEntry* entry =
178174
static_cast<EntityNodeEntry*>
179-
(PL_DHashTableSearch(&gUnicodeToEntity, NS_INT32_TO_PTR(aUnicode)));
175+
(PL_DHashTableSearch(gUnicodeToEntity, NS_INT32_TO_PTR(aUnicode)));
180176

181177
return entry ? entry->node->mStr : nullptr;
182178
}

0 commit comments

Comments
 (0)