Commit 5869469f authored by Kasimier T. Buchcik's avatar Kasimier T. Buchcik

Changed the name of the recently added public function

* xpath.c include/libxml/xpath.h runsuite.c:
  Changed the name of the recently added public function
  xmlXPathContextSetObjectCache() to
  xmlXPathContextSetCache(); so a more generic one, in
  case we decide to cache more things than only XPath
  objects.
parent df0ba264
Wed May 31 14:33:00 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
* xpath.c include/libxml/xpath.h runsuite.c:
Changed the name of the recently added public function
xmlXPathContextSetObjectCache() to
xmlXPathContextSetCache(); so a more generic one, in
case we decide to cache more things than only XPath
objects.
Tue May 30 21:36:16 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net> Tue May 30 21:36:16 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
* xpath.c: Optimized xmlXPathNodeCollectAndTest() and * xpath.c: Optimized xmlXPathNodeCollectAndTest() and
......
...@@ -343,8 +343,9 @@ struct _xmlXPathContext { ...@@ -343,8 +343,9 @@ struct _xmlXPathContext {
/* dictionnary */ /* dictionnary */
xmlDictPtr dict; /* dictionnary if any */ xmlDictPtr dict; /* dictionnary if any */
int flags; /* flags to control compilation */ int flags; /* flags to control compilation */
void *objCache; /* Cache for reusal of XPath objects. */ /* Cache for reusal of XPath objects */
void *cache;
}; };
/* /*
...@@ -490,10 +491,10 @@ XMLPUBFUN xmlXPathContextPtr XMLCALL ...@@ -490,10 +491,10 @@ XMLPUBFUN xmlXPathContextPtr XMLCALL
XMLPUBFUN void XMLCALL XMLPUBFUN void XMLCALL
xmlXPathFreeContext (xmlXPathContextPtr ctxt); xmlXPathFreeContext (xmlXPathContextPtr ctxt);
XMLPUBFUN int XMLCALL XMLPUBFUN int XMLCALL
xmlXPathContextSetObjectCache(xmlXPathContextPtr ctxt, xmlXPathContextSetCache(xmlXPathContextPtr ctxt,
int active, int active,
int maxNumberPerSlot, int value,
int options); int options);
/** /**
* Evaluation functions. * Evaluation functions.
*/ */
......
...@@ -229,12 +229,12 @@ initializeLibxml2(void) { ...@@ -229,12 +229,12 @@ initializeLibxml2(void) {
* Deactivate the cache if created; otherwise we have to create/free it * Deactivate the cache if created; otherwise we have to create/free it
* for every test, since it will confuse the memory leak detection. * for every test, since it will confuse the memory leak detection.
* Note that normally this need not be done, since the cache is not * Note that normally this need not be done, since the cache is not
* created until set explicitely with xmlXPathContextSetObjectCache(); * created until set explicitely with xmlXPathContextSetCache();
* but for test purposes it is sometimes usefull to activate the * but for test purposes it is sometimes usefull to activate the
* cache by default for the whole library. * cache by default for the whole library.
*/ */
if (ctxtXPath->objCache != NULL) if (ctxtXPath->cache != NULL)
xmlXPathContextSetObjectCache(ctxtXPath, 0, -1, 0); xmlXPathContextSetCache(ctxtXPath, 0, -1, 0);
/* used as default nanemspace in xstc tests */ /* used as default nanemspace in xstc tests */
xmlXPathRegisterNs(ctxtXPath, BAD_CAST "ts", BAD_CAST "TestSuite"); xmlXPathRegisterNs(ctxtXPath, BAD_CAST "ts", BAD_CAST "TestSuite");
xmlXPathRegisterNs(ctxtXPath, BAD_CAST "xlink", xmlXPathRegisterNs(ctxtXPath, BAD_CAST "xlink",
......
...@@ -812,11 +812,11 @@ xmlXPathCompExprAdd(ctxt->comp, (ch1), (ch2), (op), \ ...@@ -812,11 +812,11 @@ xmlXPathCompExprAdd(ctxt->comp, (ch1), (ch2), (op), \
/* #define XP_DEFAULT_CACHE_ON */ /* #define XP_DEFAULT_CACHE_ON */
#define XP_HAS_CACHE(c) ((c != NULL) && ((c)->objCache != NULL)) #define XP_HAS_CACHE(c) ((c != NULL) && ((c)->cache != NULL))
typedef struct _xmlXPathObjectCache xmlXPathObjectCache; typedef struct _xmlXPathContextCache xmlXPathContextCache;
typedef xmlXPathObjectCache *xmlXPathObjectCachePtr; typedef xmlXPathContextCache *xmlXPathContextCachePtr;
struct _xmlXPathObjectCache { struct _xmlXPathContextCache {
xmlPointerListPtr nodesetObjs; /* contains xmlXPathObjectPtr */ xmlPointerListPtr nodesetObjs; /* contains xmlXPathObjectPtr */
xmlPointerListPtr stringObjs; /* contains xmlXPathObjectPtr */ xmlPointerListPtr stringObjs; /* contains xmlXPathObjectPtr */
xmlPointerListPtr booleanObjs; /* contains xmlXPathObjectPtr */ xmlPointerListPtr booleanObjs; /* contains xmlXPathObjectPtr */
...@@ -1350,9 +1350,9 @@ static void ...@@ -1350,9 +1350,9 @@ static void
xmlXPathDebugObjUsageReset(xmlXPathContextPtr ctxt) xmlXPathDebugObjUsageReset(xmlXPathContextPtr ctxt)
{ {
if (ctxt != NULL) { if (ctxt != NULL) {
if (ctxt->objCache != NULL) { if (ctxt->cache != NULL) {
xmlXPathObjectCachePtr cache = xmlXPathContextCachePtr cache =
(xmlXPathObjectCachePtr) ctxt->objCache; (xmlXPathContextCachePtr) ctxt->cache;
cache->dbgCachedAll = 0; cache->dbgCachedAll = 0;
cache->dbgCachedNodeset = 0; cache->dbgCachedNodeset = 0;
...@@ -1425,9 +1425,9 @@ xmlXPathDebugObjUsageRequested(xmlXPathContextPtr ctxt, ...@@ -1425,9 +1425,9 @@ xmlXPathDebugObjUsageRequested(xmlXPathContextPtr ctxt,
int isCached = 0; int isCached = 0;
if (ctxt != NULL) { if (ctxt != NULL) {
if (ctxt->objCache != NULL) { if (ctxt->cache != NULL) {
xmlXPathObjectCachePtr cache = xmlXPathContextCachePtr cache =
(xmlXPathObjectCachePtr) ctxt->objCache; (xmlXPathContextCachePtr) ctxt->cache;
isCached = 1; isCached = 1;
...@@ -1579,9 +1579,9 @@ xmlXPathDebugObjUsageReleased(xmlXPathContextPtr ctxt, ...@@ -1579,9 +1579,9 @@ xmlXPathDebugObjUsageReleased(xmlXPathContextPtr ctxt,
int isCached = 0; int isCached = 0;
if (ctxt != NULL) { if (ctxt != NULL) {
if (ctxt->objCache != NULL) { if (ctxt->cache != NULL) {
xmlXPathObjectCachePtr cache = xmlXPathContextCachePtr cache =
(xmlXPathObjectCachePtr) ctxt->objCache; (xmlXPathContextCachePtr) ctxt->cache;
isCached = 1; isCached = 1;
...@@ -1683,9 +1683,9 @@ xmlXPathDebugObjUsageDisplay(xmlXPathContextPtr ctxt) ...@@ -1683,9 +1683,9 @@ xmlXPathDebugObjUsageDisplay(xmlXPathContextPtr ctxt)
printf("# XPath object usage:\n"); printf("# XPath object usage:\n");
if (ctxt != NULL) { if (ctxt != NULL) {
if (ctxt->objCache != NULL) { if (ctxt->cache != NULL) {
xmlXPathObjectCachePtr cache = xmlXPathContextCachePtr cache =
(xmlXPathObjectCachePtr) ctxt->objCache; (xmlXPathContextCachePtr) ctxt->cache;
reAll = cache->dbgReusedAll; reAll = cache->dbgReusedAll;
reqAll += reAll; reqAll += reAll;
...@@ -1779,23 +1779,23 @@ xmlXPathDebugObjUsageDisplay(xmlXPathContextPtr ctxt) ...@@ -1779,23 +1779,23 @@ xmlXPathDebugObjUsageDisplay(xmlXPathContextPtr ctxt)
************************************************************************/ ************************************************************************/
/** /**
* xmlXPathNewObjectCache: * xmlXPathNewCache:
* *
* Create a new object cache * Create a new object cache
* *
* Returns the xmlXPathObjectCahce just allocated. * Returns the xmlXPathCache just allocated.
*/ */
static xmlXPathObjectCachePtr static xmlXPathContextCachePtr
xmlXPathNewObjectCache(void) xmlXPathNewCache(void)
{ {
xmlXPathObjectCachePtr ret; xmlXPathContextCachePtr ret;
ret = (xmlXPathObjectCachePtr) xmlMalloc(sizeof(xmlXPathObjectCache)); ret = (xmlXPathContextCachePtr) xmlMalloc(sizeof(xmlXPathContextCache));
if (ret == NULL) { if (ret == NULL) {
xmlXPathErrMemory(NULL, "creating object cache\n"); xmlXPathErrMemory(NULL, "creating object cache\n");
return(NULL); return(NULL);
} }
memset(ret, 0 , (size_t) sizeof(xmlXPathObjectCache)); memset(ret, 0 , (size_t) sizeof(xmlXPathContextCache));
ret->maxNodeset = 100; ret->maxNodeset = 100;
ret->maxString = 100; ret->maxString = 100;
ret->maxBoolean = 100; ret->maxBoolean = 100;
...@@ -1805,7 +1805,7 @@ xmlXPathNewObjectCache(void) ...@@ -1805,7 +1805,7 @@ xmlXPathNewObjectCache(void)
} }
static void static void
xmlXPathFreeObjectCacheList(xmlPointerListPtr list) xmlXPathCacheFreeObjectList(xmlPointerListPtr list)
{ {
int i; int i;
xmlXPathObjectPtr obj; xmlXPathObjectPtr obj;
...@@ -1833,67 +1833,74 @@ xmlXPathFreeObjectCacheList(xmlPointerListPtr list) ...@@ -1833,67 +1833,74 @@ xmlXPathFreeObjectCacheList(xmlPointerListPtr list)
} }
static void static void
xmlXPathFreeObjectCache(xmlXPathObjectCachePtr cache) xmlXPathFreeCache(xmlXPathContextCachePtr cache)
{ {
if (cache == NULL) if (cache == NULL)
return; return;
if (cache->nodesetObjs) if (cache->nodesetObjs)
xmlXPathFreeObjectCacheList(cache->nodesetObjs); xmlXPathCacheFreeObjectList(cache->nodesetObjs);
if (cache->stringObjs) if (cache->stringObjs)
xmlXPathFreeObjectCacheList(cache->stringObjs); xmlXPathCacheFreeObjectList(cache->stringObjs);
if (cache->booleanObjs) if (cache->booleanObjs)
xmlXPathFreeObjectCacheList(cache->booleanObjs); xmlXPathCacheFreeObjectList(cache->booleanObjs);
if (cache->numberObjs) if (cache->numberObjs)
xmlXPathFreeObjectCacheList(cache->numberObjs); xmlXPathCacheFreeObjectList(cache->numberObjs);
if (cache->miscObjs) if (cache->miscObjs)
xmlXPathFreeObjectCacheList(cache->miscObjs); xmlXPathCacheFreeObjectList(cache->miscObjs);
xmlFree(cache); xmlFree(cache);
} }
/** /**
* xmlXPathContextSetObjectCache: * xmlXPathContextSetCache:
* *
* @ctxt: the XPath context * @ctxt: the XPath context
* @active: enables/disables (creates/frees) the cache * @active: enables/disables (creates/frees) the cache
* @maxNumberPerSlot: the maximum number of XPath objects to be cached per slot * @value: a value with semantics dependant on @options
* @options: currently not used * @options: options (currently only the value 0 is used)
* *
* Creates/frees an object cache on the XPath context. * Creates/frees an object cache on the XPath context.
* If activates XPath objects (xmlXPathObject) will be cached internally * If activates XPath objects (xmlXPathObject) will be cached internally
* to be reused. * to be reused.
* @maxNumberPerSlot is the maximum number of XPath objects to be cached per * @options:
* slot. There are 5 slots for: node-set, string, number, boolean, and * 0: This will set the XPath object caching:
* misc objects. Use <0 for the default number (100). * @value:
* This will set the maximum number of XPath objects
* to be cached per slot
* There are 5 slots for: node-set, string, number, boolean, and
* misc objects. Use <0 for the default number (100).
* Other values for @options have currently no effect.
* *
* Returns 0 if the setting succeeded, and -1 on API or internal errors. * Returns 0 if the setting succeeded, and -1 on API or internal errors.
*/ */
int int
xmlXPathContextSetObjectCache(xmlXPathContextPtr ctxt, xmlXPathContextSetCache(xmlXPathContextPtr ctxt,
int active, int active,
int maxNumberPerSlot, int value,
int options ATTRIBUTE_UNUSED) int options)
{ {
if (ctxt == NULL) if (ctxt == NULL)
return(-1); return(-1);
if (active) { if (active) {
xmlXPathObjectCachePtr cache; xmlXPathContextCachePtr cache;
if (ctxt->objCache == NULL) { if (ctxt->cache == NULL) {
ctxt->objCache = xmlXPathNewObjectCache(); ctxt->cache = xmlXPathNewCache();
if (ctxt->objCache == NULL) if (ctxt->cache == NULL)
return(-1); return(-1);
} }
cache = (xmlXPathObjectCachePtr) ctxt->objCache; cache = (xmlXPathContextCachePtr) ctxt->cache;
if (maxNumberPerSlot < 0) if (options == 0) {
maxNumberPerSlot = 100; if (value < 0)
cache->maxNodeset = maxNumberPerSlot; value = 100;
cache->maxString = maxNumberPerSlot; cache->maxNodeset = value;
cache->maxNumber = maxNumberPerSlot; cache->maxString = value;
cache->maxBoolean = maxNumberPerSlot; cache->maxNumber = value;
cache->maxMisc = maxNumberPerSlot; cache->maxBoolean = value;
} else if (ctxt->objCache != NULL) { cache->maxMisc = value;
xmlXPathFreeObjectCache((xmlXPathObjectCachePtr) ctxt->objCache); }
ctxt->objCache = NULL; } else if (ctxt->cache != NULL) {
xmlXPathFreeCache((xmlXPathContextCachePtr) ctxt->cache);
ctxt->cache = NULL;
} }
return(0); return(0);
} }
...@@ -1911,9 +1918,9 @@ xmlXPathContextSetObjectCache(xmlXPathContextPtr ctxt, ...@@ -1911,9 +1918,9 @@ xmlXPathContextSetObjectCache(xmlXPathContextPtr ctxt,
static xmlXPathObjectPtr static xmlXPathObjectPtr
xmlXPathCacheWrapNodeSet(xmlXPathContextPtr ctxt, xmlNodeSetPtr val) xmlXPathCacheWrapNodeSet(xmlXPathContextPtr ctxt, xmlNodeSetPtr val)
{ {
if ((ctxt != NULL) && (ctxt->objCache != NULL)) { if ((ctxt != NULL) && (ctxt->cache != NULL)) {
xmlXPathObjectCachePtr cache = xmlXPathContextCachePtr cache =
(xmlXPathObjectCachePtr) ctxt->objCache; (xmlXPathContextCachePtr) ctxt->cache;
if ((cache->miscObjs != NULL) && if ((cache->miscObjs != NULL) &&
(cache->miscObjs->number != 0)) (cache->miscObjs->number != 0))
...@@ -1948,8 +1955,8 @@ xmlXPathCacheWrapNodeSet(xmlXPathContextPtr ctxt, xmlNodeSetPtr val) ...@@ -1948,8 +1955,8 @@ xmlXPathCacheWrapNodeSet(xmlXPathContextPtr ctxt, xmlNodeSetPtr val)
static xmlXPathObjectPtr static xmlXPathObjectPtr
xmlXPathCacheWrapString(xmlXPathContextPtr ctxt, xmlChar *val) xmlXPathCacheWrapString(xmlXPathContextPtr ctxt, xmlChar *val)
{ {
if ((ctxt != NULL) && (ctxt->objCache != NULL)) { if ((ctxt != NULL) && (ctxt->cache != NULL)) {
xmlXPathObjectCachePtr cache = (xmlXPathObjectCachePtr) ctxt->objCache; xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache;
if ((cache->stringObjs != NULL) && if ((cache->stringObjs != NULL) &&
(cache->stringObjs->number != 0)) (cache->stringObjs->number != 0))
...@@ -2000,8 +2007,8 @@ xmlXPathCacheWrapString(xmlXPathContextPtr ctxt, xmlChar *val) ...@@ -2000,8 +2007,8 @@ xmlXPathCacheWrapString(xmlXPathContextPtr ctxt, xmlChar *val)
static xmlXPathObjectPtr static xmlXPathObjectPtr
xmlXPathCacheNewNodeSet(xmlXPathContextPtr ctxt, xmlNodePtr val) xmlXPathCacheNewNodeSet(xmlXPathContextPtr ctxt, xmlNodePtr val)
{ {
if ((ctxt != NULL) && (ctxt->objCache)) { if ((ctxt != NULL) && (ctxt->cache)) {
xmlXPathObjectCachePtr cache = (xmlXPathObjectCachePtr) ctxt->objCache; xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache;
if ((cache->nodesetObjs != NULL) && if ((cache->nodesetObjs != NULL) &&
(cache->nodesetObjs->number != 0)) (cache->nodesetObjs->number != 0))
...@@ -2064,8 +2071,8 @@ xmlXPathCacheNewNodeSet(xmlXPathContextPtr ctxt, xmlNodePtr val) ...@@ -2064,8 +2071,8 @@ xmlXPathCacheNewNodeSet(xmlXPathContextPtr ctxt, xmlNodePtr val)
static xmlXPathObjectPtr static xmlXPathObjectPtr
xmlXPathCacheNewCString(xmlXPathContextPtr ctxt, const char *val) xmlXPathCacheNewCString(xmlXPathContextPtr ctxt, const char *val)
{ {
if ((ctxt != NULL) && (ctxt->objCache)) { if ((ctxt != NULL) && (ctxt->cache)) {
xmlXPathObjectCachePtr cache = (xmlXPathObjectCachePtr) ctxt->objCache; xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache;
if ((cache->stringObjs != NULL) && if ((cache->stringObjs != NULL) &&
(cache->stringObjs->number != 0)) (cache->stringObjs->number != 0))
...@@ -2113,8 +2120,8 @@ xmlXPathCacheNewCString(xmlXPathContextPtr ctxt, const char *val) ...@@ -2113,8 +2120,8 @@ xmlXPathCacheNewCString(xmlXPathContextPtr ctxt, const char *val)
static xmlXPathObjectPtr static xmlXPathObjectPtr
xmlXPathCacheNewString(xmlXPathContextPtr ctxt, const xmlChar *val) xmlXPathCacheNewString(xmlXPathContextPtr ctxt, const xmlChar *val)
{ {
if ((ctxt != NULL) && (ctxt->objCache)) { if ((ctxt != NULL) && (ctxt->cache)) {
xmlXPathObjectCachePtr cache = (xmlXPathObjectCachePtr) ctxt->objCache; xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache;
if ((cache->stringObjs != NULL) && if ((cache->stringObjs != NULL) &&
(cache->stringObjs->number != 0)) (cache->stringObjs->number != 0))
...@@ -2167,8 +2174,8 @@ xmlXPathCacheNewString(xmlXPathContextPtr ctxt, const xmlChar *val) ...@@ -2167,8 +2174,8 @@ xmlXPathCacheNewString(xmlXPathContextPtr ctxt, const xmlChar *val)
static xmlXPathObjectPtr static xmlXPathObjectPtr
xmlXPathCacheNewBoolean(xmlXPathContextPtr ctxt, int val) xmlXPathCacheNewBoolean(xmlXPathContextPtr ctxt, int val)
{ {
if ((ctxt != NULL) && (ctxt->objCache)) { if ((ctxt != NULL) && (ctxt->cache)) {
xmlXPathObjectCachePtr cache = (xmlXPathObjectCachePtr) ctxt->objCache; xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache;
if ((cache->booleanObjs != NULL) && if ((cache->booleanObjs != NULL) &&
(cache->booleanObjs->number != 0)) (cache->booleanObjs->number != 0))
...@@ -2215,8 +2222,8 @@ xmlXPathCacheNewBoolean(xmlXPathContextPtr ctxt, int val) ...@@ -2215,8 +2222,8 @@ xmlXPathCacheNewBoolean(xmlXPathContextPtr ctxt, int val)
static xmlXPathObjectPtr static xmlXPathObjectPtr
xmlXPathCacheNewFloat(xmlXPathContextPtr ctxt, double val) xmlXPathCacheNewFloat(xmlXPathContextPtr ctxt, double val)
{ {
if ((ctxt != NULL) && (ctxt->objCache)) { if ((ctxt != NULL) && (ctxt->cache)) {
xmlXPathObjectCachePtr cache = (xmlXPathObjectCachePtr) ctxt->objCache; xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache;
if ((cache->numberObjs != NULL) && if ((cache->numberObjs != NULL) &&
(cache->numberObjs->number != 0)) (cache->numberObjs->number != 0))
...@@ -5129,11 +5136,11 @@ xmlXPathReleaseObject(xmlXPathContextPtr ctxt, xmlXPathObjectPtr obj) ...@@ -5129,11 +5136,11 @@ xmlXPathReleaseObject(xmlXPathContextPtr ctxt, xmlXPathObjectPtr obj)
if (obj == NULL) if (obj == NULL)
return; return;
if ((ctxt == NULL) || (ctxt->objCache == NULL)) { if ((ctxt == NULL) || (ctxt->cache == NULL)) {
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
} else { } else {
xmlXPathObjectCachePtr cache = xmlXPathContextCachePtr cache =
(xmlXPathObjectCachePtr) ctxt->objCache; (xmlXPathContextCachePtr) ctxt->cache;
switch (obj->type) { switch (obj->type) {
case XPATH_NODESET: case XPATH_NODESET:
...@@ -5737,7 +5744,7 @@ xmlXPathNewContext(xmlDocPtr doc) { ...@@ -5737,7 +5744,7 @@ xmlXPathNewContext(xmlDocPtr doc) {
ret->proximityPosition = -1; ret->proximityPosition = -1;
#ifdef XP_DEFAULT_CACHE_ON #ifdef XP_DEFAULT_CACHE_ON
if (xmlXPathContextSetObjectCache(ret, 1, -1, 0) == -1) { if (xmlXPathContextSetCache(ret, 1, -1, 0) == -1) {
xmlXPathFreeContext(ret); xmlXPathFreeContext(ret);
return(NULL); return(NULL);
} }
...@@ -5758,8 +5765,8 @@ void ...@@ -5758,8 +5765,8 @@ void
xmlXPathFreeContext(xmlXPathContextPtr ctxt) { xmlXPathFreeContext(xmlXPathContextPtr ctxt) {
if (ctxt == NULL) return; if (ctxt == NULL) return;
if (ctxt->objCache != NULL) if (ctxt->cache != NULL)
xmlXPathFreeObjectCache((xmlXPathObjectCachePtr) ctxt->objCache); xmlXPathFreeCache((xmlXPathContextCachePtr) ctxt->cache);
xmlXPathRegisteredNsCleanup(ctxt); xmlXPathRegisteredNsCleanup(ctxt);
xmlXPathRegisteredFuncsCleanup(ctxt); xmlXPathRegisteredFuncsCleanup(ctxt);
xmlXPathRegisteredVariablesCleanup(ctxt); xmlXPathRegisteredVariablesCleanup(ctxt);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment