From d3a2e4c2b34fa2e8ee056b04a685610483ffd1c4 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Tue, 30 Sep 2003 13:38:04 +0000 Subject: [PATCH] made the predefined entities static predefined structures to avoid the * entities.c legacy.c parser.c: made the predefined entities static predefined structures to avoid the work, memory and hazards associated to initialization/cleanup. Daniel --- ChangeLog | 6 +++ entities.c | 126 +++++++++++++++++++++++++---------------------------- legacy.c | 22 +++++++++- parser.c | 2 - 4 files changed, 86 insertions(+), 70 deletions(-) diff --git a/ChangeLog b/ChangeLog index eedcb951..22611e9f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Tue Sep 30 15:34:31 CEST 2003 Daniel Veillard + + * entities.c legacy.c parser.c: made the predefined entities + static predefined structures to avoid the work, memory and + hazards associated to initialization/cleanup. + Tue Sep 30 14:30:47 CEST 2003 Daniel Veillard * HTMLparser.c Makefile.am configure.in legacy.c parser.c diff --git a/entities.c b/entities.c index ff0dff85..9d1f1659 100644 --- a/entities.c +++ b/entities.c @@ -24,23 +24,41 @@ * The XML predefined entities. */ -struct xmlPredefinedEntityValue { - const char *name; - const char *value; +static xmlEntity xmlEntityLt = { + NULL, XML_ENTITY_DECL, BAD_CAST "lt", + NULL, NULL, NULL, NULL, NULL, NULL, + BAD_CAST "<", BAD_CAST "<", 1, + XML_INTERNAL_PREDEFINED_ENTITY, + NULL, NULL, NULL, NULL, 0 }; -static struct xmlPredefinedEntityValue xmlPredefinedEntityValues[] = { - { "lt", "<" }, - { "gt", ">" }, - { "apos", "'" }, - { "quot", "\"" }, - { "amp", "&" } +static xmlEntity xmlEntityGt = { + NULL, XML_ENTITY_DECL, BAD_CAST "gt", + NULL, NULL, NULL, NULL, NULL, NULL, + BAD_CAST ">", BAD_CAST ">", 1, + XML_INTERNAL_PREDEFINED_ENTITY, + NULL, NULL, NULL, NULL, 0 +}; +static xmlEntity xmlEntityAmp = { + NULL, XML_ENTITY_DECL, BAD_CAST "amp", + NULL, NULL, NULL, NULL, NULL, NULL, + BAD_CAST "&", BAD_CAST "&", 1, + XML_INTERNAL_PREDEFINED_ENTITY, + NULL, NULL, NULL, NULL, 0 +}; +static xmlEntity xmlEntityQuot = { + NULL, XML_ENTITY_DECL, BAD_CAST "quot", + NULL, NULL, NULL, NULL, NULL, NULL, + BAD_CAST "\"", BAD_CAST "\"", 1, + XML_INTERNAL_PREDEFINED_ENTITY, + NULL, NULL, NULL, NULL, 0 +}; +static xmlEntity xmlEntityApos = { + NULL, XML_ENTITY_DECL, BAD_CAST "apos", + NULL, NULL, NULL, NULL, NULL, NULL, + BAD_CAST "'", BAD_CAST "'", 1, + XML_INTERNAL_PREDEFINED_ENTITY, + NULL, NULL, NULL, NULL, 0 }; - -/* - * TODO: This is GROSS, allocation of a 256 entry hash for - * a fixed number of 4 elements ! - */ -static xmlHashTablePtr xmlPredefinedEntities = NULL; /* * xmlFreeEntity : clean-up an entity record. @@ -93,9 +111,7 @@ xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type, table = dtd->pentities; break; case XML_INTERNAL_PREDEFINED_ENTITY: - if (xmlPredefinedEntities == NULL) - xmlPredefinedEntities = xmlHashCreate(8); - table = xmlPredefinedEntities; + return(NULL); } if (table == NULL) return(NULL); @@ -139,48 +155,6 @@ xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type, return(ret); } -/** - * xmlInitializePredefinedEntities: - * - * Set up the predefined entities. - */ -void xmlInitializePredefinedEntities(void) { - unsigned int i; - xmlChar name[50]; - xmlChar value[50]; - const char *in; - xmlChar *out; - - if (xmlPredefinedEntities != NULL) return; - - xmlPredefinedEntities = xmlCreateEntitiesTable(); - for (i = 0;i < sizeof(xmlPredefinedEntityValues) / - sizeof(xmlPredefinedEntityValues[0]);i++) { - in = xmlPredefinedEntityValues[i].name; - out = &name[0]; - for (;(*out++ = (xmlChar) *in);)in++; - in = xmlPredefinedEntityValues[i].value; - out = &value[0]; - for (;(*out++ = (xmlChar) *in);)in++; - - xmlAddEntity(NULL, (const xmlChar *) &name[0], - XML_INTERNAL_PREDEFINED_ENTITY, NULL, NULL, - &value[0]); - } -} - -/** - * xmlCleanupPredefinedEntities: - * - * Cleanup up the predefined entities table. - */ -void xmlCleanupPredefinedEntities(void) { - if (xmlPredefinedEntities == NULL) return; - - xmlFreeEntitiesTable(xmlPredefinedEntities); - xmlPredefinedEntities = NULL; -} - /** * xmlGetPredefinedEntity: * @name: the entity name @@ -191,9 +165,30 @@ void xmlCleanupPredefinedEntities(void) { */ xmlEntityPtr xmlGetPredefinedEntity(const xmlChar *name) { - if (xmlPredefinedEntities == NULL) - xmlInitializePredefinedEntities(); - return((xmlEntityPtr) xmlHashLookup(xmlPredefinedEntities, name)); + if (name == NULL) return(NULL); + switch (name[0]) { + case 'l': + if (xmlStrEqual(name, BAD_CAST "lt")) + return(&xmlEntityLt); + break; + case 'g': + if (xmlStrEqual(name, BAD_CAST "gt")) + return(&xmlEntityGt); + break; + case 'a': + if (xmlStrEqual(name, BAD_CAST "amp")) + return(&xmlEntityAmp); + if (xmlStrEqual(name, BAD_CAST "apos")) + return(&xmlEntityApos); + break; + case 'q': + if (xmlStrEqual(name, BAD_CAST "quot")) + return(&xmlEntityQuot); + break; + default: + break; + } + return(NULL); } /** @@ -397,10 +392,7 @@ xmlGetDocEntity(xmlDocPtr doc, const xmlChar *name) { } } } - if (xmlPredefinedEntities == NULL) - xmlInitializePredefinedEntities(); - table = xmlPredefinedEntities; - return(xmlGetEntityFromTable(table, name)); + return(xmlGetPredefinedEntity(name)); } /* diff --git a/legacy.c b/legacy.c index 3d29c984..e0f533eb 100644 --- a/legacy.c +++ b/legacy.c @@ -10,12 +10,14 @@ #define IN_LIBXML #include "libxml.h" +#ifdef LIBXML_LEGACY_ENABLED +#include + #include #include #include #include -#ifdef LIBXML_LEGACY_ENABLED void xmlUpgradeOldNs(xmlDocPtr doc); /************************************************************************ @@ -24,6 +26,24 @@ void xmlUpgradeOldNs(xmlDocPtr doc); * * ************************************************************************/ +/** + * xmlInitializePredefinedEntities: + * + * Set up the predefined entities. + * Deprecated call + */ +void xmlInitializePredefinedEntities(void) { +} + +/** + * xmlCleanupPredefinedEntities: + * + * Cleanup up the predefined entities table. + * Deprecated call + */ +void xmlCleanupPredefinedEntities(void) { +} + static const char *xmlFeaturesList[] = { "validate", "load subset", diff --git a/parser.c b/parser.c index a018692f..f3709971 100644 --- a/parser.c +++ b/parser.c @@ -12022,7 +12022,6 @@ xmlInitParser(void) { xmlInitThreads(); xmlInitMemory(); xmlInitCharEncodingHandlers(); - xmlInitializePredefinedEntities(); xmlDefaultSAXHandlerInit(); xmlRegisterDefaultInputCallbacks(); #ifdef LIBXML_OUTPUT_ENABLED @@ -12055,7 +12054,6 @@ xmlCleanupParser(void) { return; xmlCleanupCharEncodingHandlers(); - xmlCleanupPredefinedEntities(); #ifdef LIBXML_CATALOG_ENABLED xmlCatalogCleanup(); #endif