Added an XPath object cache. It sits on an xmlXPathContext and need to be

* xpath.c include/libxml/xpath.h: Added an XPath object cache.
  It sits on an xmlXPathContext and need to be explicitely
  activated (or deactivated again) with
  xmlXPathContextSetObjectCache(). The cache consists of 5
  lists for node-set, string, number, boolean and misc XPath
  objects. Internally the xpath.c module will use object-
  deposition and -acquisition functions which will try to reuse
  as many XPath objects as possible, and fallback to normal
  free/create behaviour if no cache is available or if the cache
  is full.
* runsuite.c: Adjusted to deactivate the cache for XML Schema
  tests if a cache-creation is turned on by default for the whole
  library, e.g. for testing purposes of the cache. It is
  deactivated here in order to avoid confusion of the memory leak
  detection in runsuite.c.
This commit is contained in:
Kasimier T. Buchcik 2006-05-29 16:15:36 +00:00
parent 984a9aeddf
commit a72484438f
4 changed files with 1812 additions and 285 deletions

View File

@ -1,3 +1,21 @@
Mon May 29 18:06:17 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
* xpath.c include/libxml/xpath.h: Added an XPath object cache.
It sits on an xmlXPathContext and need to be explicitely
activated (or deactivated again) with
xmlXPathContextSetObjectCache(). The cache consists of 5
lists for node-set, string, number, boolean and misc XPath
objects. Internally the xpath.c module will use object-
deposition and -acquisition functions which will try to reuse
as many XPath objects as possible, and fallback to normal
free/create behaviour if no cache is available or if the cache
is full.
* runsuite.c: Adjusted to deactivate the cache for XML Schema
tests if a cache-creation is turned on by default for the whole
library, e.g. for testing purposes of the cache. It is
deactivated here in order to avoid confusion of the memory leak
detection in runsuite.c.
Wed May 24 10:54:25 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
* xpath.c: Removed a memcpy if xmlXPathNodeSetMerge(); it

View File

@ -35,6 +35,7 @@ extern "C" {
#endif /* LIBXML_XPATH_ENABLED or LIBXML_SCHEMAS_ENABLED */
#ifdef LIBXML_XPATH_ENABLED
typedef struct _xmlXPathContext xmlXPathContext;
typedef xmlXPathContext *xmlXPathContextPtr;
typedef struct _xmlXPathParserContext xmlXPathParserContext;
@ -343,6 +344,7 @@ struct _xmlXPathContext {
xmlDictPtr dict; /* dictionnary if any */
int flags; /* flags to control compilation */
void *objCache; /* Cache for reusal of XPath objects. */
};
/*
@ -485,9 +487,13 @@ XMLPUBFUN xmlXPathObjectPtr XMLCALL
*/
XMLPUBFUN xmlXPathContextPtr XMLCALL
xmlXPathNewContext (xmlDocPtr doc);
XMLPUBFUN void XMLCALL
XMLPUBFUN void XMLCALL
xmlXPathFreeContext (xmlXPathContextPtr ctxt);
XMLPUBFUN int XMLCALL
xmlXPathContextSetObjectCache(xmlXPathContextPtr ctxt,
int active,
int maxNumberPerSlot,
int options);
/**
* Evaluation functions.
*/

View File

@ -225,6 +225,16 @@ initializeLibxml2(void) {
xmlInitParser();
xmlSetExternalEntityLoader(testExternalEntityLoader);
ctxtXPath = xmlXPathNewContext(NULL);
/*
* Deactivate the cache if created; otherwise we have to create/free it
* for every test, since it will confuse the memory leak detection.
* Note that normally this need not be done, since the cache is not
* created until set explicitely with xmlXPathContextSetObjectCache();
* but for test purposes it is sometimes usefull to activate the
* cache by default for the whole library.
*/
if (ctxtXPath->objCache != NULL)
xmlXPathContextSetObjectCache(ctxtXPath, 0, -1, 0);
/* used as default nanemspace in xstc tests */
xmlXPathRegisterNs(ctxtXPath, BAD_CAST "ts", BAD_CAST "TestSuite");
xmlXPathRegisterNs(ctxtXPath, BAD_CAST "xlink",
@ -1158,7 +1168,6 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
printf("Total %d tests, %d errors, %d leaks\n",
nb_tests, nb_errors, nb_leaks);
}
xmlXPathFreeContext(ctxtXPath);
xmlCleanupParser();
xmlMemoryDump();

2058
xpath.c

File diff suppressed because it is too large Load Diff