📄 xpath.c
字号:
case XPATH_POINT: cache->dbgReusedPoint++; break; case XPATH_RANGE: cache->dbgReusedRange++; break; case XPATH_LOCATIONSET: cache->dbgReusedLocset++; break; case XPATH_USERS: cache->dbgReusedUsers++; break; case XPATH_XSLT_TREE: cache->dbgReusedXSLTTree++; break; default: break; } } } switch (objType) { case XPATH_UNDEFINED: if (! isCached) xmlXPathDebugObjTotalUndefined++; xmlXPathDebugObjCounterUndefined++; if (xmlXPathDebugObjCounterUndefined > xmlXPathDebugObjMaxUndefined) xmlXPathDebugObjMaxUndefined = xmlXPathDebugObjCounterUndefined; break; case XPATH_NODESET: if (! isCached) xmlXPathDebugObjTotalNodeset++; xmlXPathDebugObjCounterNodeset++; if (xmlXPathDebugObjCounterNodeset > xmlXPathDebugObjMaxNodeset) xmlXPathDebugObjMaxNodeset = xmlXPathDebugObjCounterNodeset; break; case XPATH_BOOLEAN: if (! isCached) xmlXPathDebugObjTotalBool++; xmlXPathDebugObjCounterBool++; if (xmlXPathDebugObjCounterBool > xmlXPathDebugObjMaxBool) xmlXPathDebugObjMaxBool = xmlXPathDebugObjCounterBool; break; case XPATH_NUMBER: if (! isCached) xmlXPathDebugObjTotalNumber++; xmlXPathDebugObjCounterNumber++; if (xmlXPathDebugObjCounterNumber > xmlXPathDebugObjMaxNumber) xmlXPathDebugObjMaxNumber = xmlXPathDebugObjCounterNumber; break; case XPATH_STRING: if (! isCached) xmlXPathDebugObjTotalString++; xmlXPathDebugObjCounterString++; if (xmlXPathDebugObjCounterString > xmlXPathDebugObjMaxString) xmlXPathDebugObjMaxString = xmlXPathDebugObjCounterString; break; case XPATH_POINT: if (! isCached) xmlXPathDebugObjTotalPoint++; xmlXPathDebugObjCounterPoint++; if (xmlXPathDebugObjCounterPoint > xmlXPathDebugObjMaxPoint) xmlXPathDebugObjMaxPoint = xmlXPathDebugObjCounterPoint; break; case XPATH_RANGE: if (! isCached) xmlXPathDebugObjTotalRange++; xmlXPathDebugObjCounterRange++; if (xmlXPathDebugObjCounterRange > xmlXPathDebugObjMaxRange) xmlXPathDebugObjMaxRange = xmlXPathDebugObjCounterRange; break; case XPATH_LOCATIONSET: if (! isCached) xmlXPathDebugObjTotalLocset++; xmlXPathDebugObjCounterLocset++; if (xmlXPathDebugObjCounterLocset > xmlXPathDebugObjMaxLocset) xmlXPathDebugObjMaxLocset = xmlXPathDebugObjCounterLocset; break; case XPATH_USERS: if (! isCached) xmlXPathDebugObjTotalUsers++; xmlXPathDebugObjCounterUsers++; if (xmlXPathDebugObjCounterUsers > xmlXPathDebugObjMaxUsers) xmlXPathDebugObjMaxUsers = xmlXPathDebugObjCounterUsers; break; case XPATH_XSLT_TREE: if (! isCached) xmlXPathDebugObjTotalXSLTTree++; xmlXPathDebugObjCounterXSLTTree++; if (xmlXPathDebugObjCounterXSLTTree > xmlXPathDebugObjMaxXSLTTree) xmlXPathDebugObjMaxXSLTTree = xmlXPathDebugObjCounterXSLTTree; break; default: break; } if (! isCached) xmlXPathDebugObjTotalAll++; xmlXPathDebugObjCounterAll++; if (xmlXPathDebugObjCounterAll > xmlXPathDebugObjMaxAll) xmlXPathDebugObjMaxAll = xmlXPathDebugObjCounterAll;}static voidxmlXPathDebugObjUsageReleased(xmlXPathContextPtr ctxt, xmlXPathObjectType objType){ int isCached = 0; if (ctxt != NULL) { if (ctxt->cache != NULL) { xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache; isCached = 1; cache->dbgCachedAll++; switch (objType) { case XPATH_UNDEFINED: cache->dbgCachedUndefined++; break; case XPATH_NODESET: cache->dbgCachedNodeset++; break; case XPATH_BOOLEAN: cache->dbgCachedBool++; break; case XPATH_NUMBER: cache->dbgCachedNumber++; break; case XPATH_STRING: cache->dbgCachedString++; break; case XPATH_POINT: cache->dbgCachedPoint++; break; case XPATH_RANGE: cache->dbgCachedRange++; break; case XPATH_LOCATIONSET: cache->dbgCachedLocset++; break; case XPATH_USERS: cache->dbgCachedUsers++; break; case XPATH_XSLT_TREE: cache->dbgCachedXSLTTree++; break; default: break; } } } switch (objType) { case XPATH_UNDEFINED: xmlXPathDebugObjCounterUndefined--; break; case XPATH_NODESET: xmlXPathDebugObjCounterNodeset--; break; case XPATH_BOOLEAN: xmlXPathDebugObjCounterBool--; break; case XPATH_NUMBER: xmlXPathDebugObjCounterNumber--; break; case XPATH_STRING: xmlXPathDebugObjCounterString--; break; case XPATH_POINT: xmlXPathDebugObjCounterPoint--; break; case XPATH_RANGE: xmlXPathDebugObjCounterRange--; break; case XPATH_LOCATIONSET: xmlXPathDebugObjCounterLocset--; break; case XPATH_USERS: xmlXPathDebugObjCounterUsers--; break; case XPATH_XSLT_TREE: xmlXPathDebugObjCounterXSLTTree--; break; default: break; } xmlXPathDebugObjCounterAll--;}/* REVISIT TODO: Make this static when committing */static voidxmlXPathDebugObjUsageDisplay(xmlXPathContextPtr ctxt){ int reqAll, reqNodeset, reqString, reqBool, reqNumber, reqXSLTTree, reqUndefined; int caAll = 0, caNodeset = 0, caString = 0, caBool = 0, caNumber = 0, caXSLTTree = 0, caUndefined = 0; int reAll = 0, reNodeset = 0, reString = 0, reBool = 0, reNumber = 0, reXSLTTree = 0, reUndefined = 0; int leftObjs = xmlXPathDebugObjCounterAll; reqAll = xmlXPathDebugObjTotalAll; reqNodeset = xmlXPathDebugObjTotalNodeset; reqString = xmlXPathDebugObjTotalString; reqBool = xmlXPathDebugObjTotalBool; reqNumber = xmlXPathDebugObjTotalNumber; reqXSLTTree = xmlXPathDebugObjTotalXSLTTree; reqUndefined = xmlXPathDebugObjTotalUndefined; printf("# XPath object usage:\n"); if (ctxt != NULL) { if (ctxt->cache != NULL) { xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache; reAll = cache->dbgReusedAll; reqAll += reAll; reNodeset = cache->dbgReusedNodeset; reqNodeset += reNodeset; reString = cache->dbgReusedString; reqString += reString; reBool = cache->dbgReusedBool; reqBool += reBool; reNumber = cache->dbgReusedNumber; reqNumber += reNumber; reXSLTTree = cache->dbgReusedXSLTTree; reqXSLTTree += reXSLTTree; reUndefined = cache->dbgReusedUndefined; reqUndefined += reUndefined; caAll = cache->dbgCachedAll; caBool = cache->dbgCachedBool; caNodeset = cache->dbgCachedNodeset; caString = cache->dbgCachedString; caNumber = cache->dbgCachedNumber; caXSLTTree = cache->dbgCachedXSLTTree; caUndefined = cache->dbgCachedUndefined; if (cache->nodesetObjs) leftObjs -= cache->nodesetObjs->number; if (cache->stringObjs) leftObjs -= cache->stringObjs->number; if (cache->booleanObjs) leftObjs -= cache->booleanObjs->number; if (cache->numberObjs) leftObjs -= cache->numberObjs->number; if (cache->miscObjs) leftObjs -= cache->miscObjs->number; } } printf("# all\n"); printf("# total : %d\n", reqAll); printf("# left : %d\n", leftObjs); printf("# created: %d\n", xmlXPathDebugObjTotalAll); printf("# reused : %d\n", reAll); printf("# max : %d\n", xmlXPathDebugObjMaxAll); printf("# node-sets\n"); printf("# total : %d\n", reqNodeset); printf("# created: %d\n", xmlXPathDebugObjTotalNodeset); printf("# reused : %d\n", reNodeset); printf("# max : %d\n", xmlXPathDebugObjMaxNodeset); printf("# strings\n"); printf("# total : %d\n", reqString); printf("# created: %d\n", xmlXPathDebugObjTotalString); printf("# reused : %d\n", reString); printf("# max : %d\n", xmlXPathDebugObjMaxString); printf("# booleans\n"); printf("# total : %d\n", reqBool); printf("# created: %d\n", xmlXPathDebugObjTotalBool); printf("# reused : %d\n", reBool); printf("# max : %d\n", xmlXPathDebugObjMaxBool); printf("# numbers\n"); printf("# total : %d\n", reqNumber); printf("# created: %d\n", xmlXPathDebugObjTotalNumber); printf("# reused : %d\n", reNumber); printf("# max : %d\n", xmlXPathDebugObjMaxNumber); printf("# XSLT result tree fragments\n"); printf("# total : %d\n", reqXSLTTree); printf("# created: %d\n", xmlXPathDebugObjTotalXSLTTree); printf("# reused : %d\n", reXSLTTree); printf("# max : %d\n", xmlXPathDebugObjMaxXSLTTree); printf("# undefined\n"); printf("# total : %d\n", reqUndefined); printf("# created: %d\n", xmlXPathDebugObjTotalUndefined); printf("# reused : %d\n", reUndefined); printf("# max : %d\n", xmlXPathDebugObjMaxUndefined);}#endif /* XP_DEBUG_OBJ_USAGE */#endif /* LIBXML_DEBUG_ENABLED *//************************************************************************ * * * XPath object caching * * * ************************************************************************//** * xmlXPathNewCache: * * Create a new object cache * * Returns the xmlXPathCache just allocated. */static xmlXPathContextCachePtrxmlXPathNewCache(void){ xmlXPathContextCachePtr ret; ret = (xmlXPathContextCachePtr) xmlMalloc(sizeof(xmlXPathContextCache)); if (ret == NULL) { xmlXPathErrMemory(NULL, "creating object cache\n"); return(NULL); } memset(ret, 0 , (size_t) sizeof(xmlXPathContextCache)); ret->maxNodeset = 100; ret->maxString = 100; ret->maxBoolean = 100; ret->maxNumber = 100; ret->maxMisc = 100; return(ret);}static voidxmlXPathCacheFreeObjectList(xmlPointerListPtr list){ int i; xmlXPathObjectPtr obj; if (list == NULL) return; for (i = 0; i < list->number; i++) { obj = list->items[i]; /* * Note that it is already assured that we don't need to * look out for namespace nodes in the node-set. */ if (obj->nodesetval != NULL) { if (obj->nodesetval->nodeTab != NULL) xmlFree(obj->nodesetval->nodeTab); xmlFree(obj->nodesetval); } xmlFree(obj);#ifdef XP_DEBUG_OBJ_USAGE xmlXPathDebugObjCounterAll--;#endif } xmlPointerListFree(list);}static voidxmlXPathFreeCache(xmlXPathContextCachePtr cache){ if (cache == NULL) return; if (cache->nodesetObjs) xmlXPathCacheFreeObjectList(cache->nodesetObjs); if (cache->stringObjs) xmlXPathCacheFreeObjectList(cache->stringObjs); if (cache->booleanObjs) xmlXPathCacheFreeObjectList(cache->booleanObjs); if (cache->numberObjs) xmlXPathCacheFreeObjectList(cache->numberObjs); if (cache->miscObjs) xmlXPathCacheFreeObjectList(cache->miscObjs); xmlFree(cache);}/** * xmlXPathContextSetCache: * * @ctxt: the XPath context * @active: enables/disables (creates/frees) the cache * @value: a value with semantics dependant on @options * @options: options (currently only the value 0 is used) * * Creates/frees an object cache on the XPath context. * If activates XPath objects (xmlXPathObject) will be cached internally * to be reused. * @options: * 0: This will set the XPath object caching: * @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. */intxmlXPathContextSetCache(xmlXPathContextPtr ctxt, int active, int value, int options){ if (ctxt == NULL) return(-1); if (active) { xmlXPathContextCachePtr cache; if (ctxt->cache == NULL) { ctxt->cache = xmlXPathNewCache(); if (ctxt->cache == NULL) return(-1); } cache = (xmlXPathContextCachePtr) ctxt->cache; if (options == 0) { if (value < 0) value = 100; cache->maxNodeset = value; cache->maxString = value; cache->maxNumber = value; cache->maxBoolean = value; cache->maxMisc = value; } } else if (ctxt->cache != NULL) { xmlXPathFreeCache((xmlXPathContextCachePtr) ctxt->cache); ctxt->cache = NULL; } return(0);}/** * xmlXPathCacheWrapNodeSet: * @ctxt: the XPath context * @val: the NodePtr value * * This is the cached version of xmlXPathWrapNodeSet(). * Wrap the Nodeset @val in a new xmlXPathObjectPtr * * Returns the created or reused object. */static xmlXPathObjectPtrxmlXPathCacheWrapNodeSet(xmlXPathContextPtr ctxt, xmlNodeSetPtr val){ if ((ctxt != NULL) && (ctxt->cache != NULL)) { xmlXPathContextCachePtr cache = (xmlXPathContextCachePtr) ctxt->cache; if ((cache->miscObjs != NULL) && (cache->miscObjs->number != 0)) { xmlXPathObjectPtr ret; ret = (xmlXPathObjectPtr) cache->miscObjs->items[--cache->miscObjs->number]; ret->type = XPATH_NODESET; ret->nodesetval = val;#ifdef XP_DEBUG_OBJ_USAGE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -