diff --git a/mozilla/htmlparser/src/nsHTMLEntities.cpp b/mozilla/htmlparser/src/nsHTMLEntities.cpp
index 508dddc577e..a87b388167b 100644
--- a/mozilla/htmlparser/src/nsHTMLEntities.cpp
+++ b/mozilla/htmlparser/src/nsHTMLEntities.cpp
@@ -119,8 +119,9 @@ static const PLDHashTableOps UnicodeToEntityOps = {
nsnull,
};
-PLDHashTable gEntityToUnicode = { 0 };
-PLDHashTable gUnicodeToEntity = { 0 };
+static PLDHashTable gEntityToUnicode = { 0 };
+static PLDHashTable gUnicodeToEntity = { 0 };
+static nsrefcnt gTableRefCnt = 0;
#define HTML_ENTITY(_name, _value) { #_name, _value },
static const EntityNode gEntityArray[] = {
@@ -128,46 +129,54 @@ static const EntityNode gEntityArray[] = {
};
#undef HTML_ENTITY
-#define NS_HTML_ENTITY_COUNT ((PRInt32)(sizeof(gEntityArray) / sizeof(gEntityArray[0])))
+#define NS_HTML_ENTITY_COUNT ((PRInt32)NS_ARRAY_LENGTH(gEntityArray))
void
nsHTMLEntities::AddRefTable(void)
{
- if (!gEntityToUnicode.ops)
- PL_DHashTableInit(&gEntityToUnicode, &EntityToUnicodeOps,
- nsnull, sizeof(EntityNodeEntry), NS_HTML_ENTITY_COUNT);
-
- if (!gUnicodeToEntity.ops)
- PL_DHashTableInit(&gUnicodeToEntity, &UnicodeToEntityOps,
- nsnull, sizeof(EntityNodeEntry), NS_HTML_ENTITY_COUNT);
+ if (++gTableRefCnt != 1)
+ return;
- PRUint32 i;
- for (i=0; iUnicode table
entry = NS_STATIC_CAST(EntityNodeEntry*,
PL_DHashTableOperate(&gEntityToUnicode,
- gEntityArray[i].mStr,
+ node->mStr,
PL_DHASH_ADD));
NS_ASSERTION(entry, "Error adding an entry");
- entry->node = &gEntityArray[i];
+ // Prefer earlier entries when we have duplication.
+ if (!entry->node)
+ entry->node = node;
// add to Unicode->Entity table
entry = NS_STATIC_CAST(EntityNodeEntry*,
PL_DHashTableOperate(&gUnicodeToEntity,
- NS_INT32_TO_PTR(gEntityArray[i].mUnicode),
+ NS_INT32_TO_PTR(node->mUnicode),
PL_DHASH_ADD));
NS_ASSERTION(entry, "Error adding an entry");
- entry->node = &gEntityArray[i];
-
+ // Prefer earlier entries when we have duplication.
+ if (!entry->node)
+ entry->node = node;
}
-
}
void
nsHTMLEntities::ReleaseTable(void)
{
+ if (--gTableRefCnt != 0)
+ return;
+
if (gEntityToUnicode.ops) {
PL_DHashTableFinish(&gEntityToUnicode);
gEntityToUnicode.ops = nsnull;
diff --git a/mozilla/htmlparser/src/nsHTMLEntityList.h b/mozilla/htmlparser/src/nsHTMLEntityList.h
index 5ef2b97db53..b88de9c985b 100644
--- a/mozilla/htmlparser/src/nsHTMLEntityList.h
+++ b/mozilla/htmlparser/src/nsHTMLEntityList.h
@@ -316,8 +316,15 @@ HTML_ENTITY(lsaquo, 8249)
HTML_ENTITY(rsaquo, 8250)
HTML_ENTITY(euro, 8364)
-// Navigator entity extensions; apos is from XML
+// Navigator entity extensions
+// This block of entities needs to be at the bottom of the list since it
+// contains duplicate Unicode codepoints. The codepoint to entity name
+// mapping (used by Composer) must ignores them, which occurs only
+// because they are listed later.
+
+// apos is from XML
HTML_ENTITY(apos, 39)
+// The capitalized versions are required to handle non-standard input.
HTML_ENTITY(AMP, 38)
HTML_ENTITY(COPY, 169)
HTML_ENTITY(GT, 62)
diff --git a/mozilla/parser/htmlparser/src/nsHTMLEntities.cpp b/mozilla/parser/htmlparser/src/nsHTMLEntities.cpp
index 508dddc577e..a87b388167b 100644
--- a/mozilla/parser/htmlparser/src/nsHTMLEntities.cpp
+++ b/mozilla/parser/htmlparser/src/nsHTMLEntities.cpp
@@ -119,8 +119,9 @@ static const PLDHashTableOps UnicodeToEntityOps = {
nsnull,
};
-PLDHashTable gEntityToUnicode = { 0 };
-PLDHashTable gUnicodeToEntity = { 0 };
+static PLDHashTable gEntityToUnicode = { 0 };
+static PLDHashTable gUnicodeToEntity = { 0 };
+static nsrefcnt gTableRefCnt = 0;
#define HTML_ENTITY(_name, _value) { #_name, _value },
static const EntityNode gEntityArray[] = {
@@ -128,46 +129,54 @@ static const EntityNode gEntityArray[] = {
};
#undef HTML_ENTITY
-#define NS_HTML_ENTITY_COUNT ((PRInt32)(sizeof(gEntityArray) / sizeof(gEntityArray[0])))
+#define NS_HTML_ENTITY_COUNT ((PRInt32)NS_ARRAY_LENGTH(gEntityArray))
void
nsHTMLEntities::AddRefTable(void)
{
- if (!gEntityToUnicode.ops)
- PL_DHashTableInit(&gEntityToUnicode, &EntityToUnicodeOps,
- nsnull, sizeof(EntityNodeEntry), NS_HTML_ENTITY_COUNT);
-
- if (!gUnicodeToEntity.ops)
- PL_DHashTableInit(&gUnicodeToEntity, &UnicodeToEntityOps,
- nsnull, sizeof(EntityNodeEntry), NS_HTML_ENTITY_COUNT);
+ if (++gTableRefCnt != 1)
+ return;
- PRUint32 i;
- for (i=0; iUnicode table
entry = NS_STATIC_CAST(EntityNodeEntry*,
PL_DHashTableOperate(&gEntityToUnicode,
- gEntityArray[i].mStr,
+ node->mStr,
PL_DHASH_ADD));
NS_ASSERTION(entry, "Error adding an entry");
- entry->node = &gEntityArray[i];
+ // Prefer earlier entries when we have duplication.
+ if (!entry->node)
+ entry->node = node;
// add to Unicode->Entity table
entry = NS_STATIC_CAST(EntityNodeEntry*,
PL_DHashTableOperate(&gUnicodeToEntity,
- NS_INT32_TO_PTR(gEntityArray[i].mUnicode),
+ NS_INT32_TO_PTR(node->mUnicode),
PL_DHASH_ADD));
NS_ASSERTION(entry, "Error adding an entry");
- entry->node = &gEntityArray[i];
-
+ // Prefer earlier entries when we have duplication.
+ if (!entry->node)
+ entry->node = node;
}
-
}
void
nsHTMLEntities::ReleaseTable(void)
{
+ if (--gTableRefCnt != 0)
+ return;
+
if (gEntityToUnicode.ops) {
PL_DHashTableFinish(&gEntityToUnicode);
gEntityToUnicode.ops = nsnull;
diff --git a/mozilla/parser/htmlparser/src/nsHTMLEntityList.h b/mozilla/parser/htmlparser/src/nsHTMLEntityList.h
index 5ef2b97db53..b88de9c985b 100644
--- a/mozilla/parser/htmlparser/src/nsHTMLEntityList.h
+++ b/mozilla/parser/htmlparser/src/nsHTMLEntityList.h
@@ -316,8 +316,15 @@ HTML_ENTITY(lsaquo, 8249)
HTML_ENTITY(rsaquo, 8250)
HTML_ENTITY(euro, 8364)
-// Navigator entity extensions; apos is from XML
+// Navigator entity extensions
+// This block of entities needs to be at the bottom of the list since it
+// contains duplicate Unicode codepoints. The codepoint to entity name
+// mapping (used by Composer) must ignores them, which occurs only
+// because they are listed later.
+
+// apos is from XML
HTML_ENTITY(apos, 39)
+// The capitalized versions are required to handle non-standard input.
HTML_ENTITY(AMP, 38)
HTML_ENTITY(COPY, 169)
HTML_ENTITY(GT, 62)