From a8673fb74375089a432aa23230396335a46df5d3 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Sun, 8 Mar 2020 16:41:33 +0100 Subject: Remove dead code and fix more warnings --- qtools/qglobal.h | 1 - src/CMakeLists.txt | 1 - src/doxygen.cpp | 1 - src/doxygen.h | 1 - src/latexgen.cpp | 10 +- src/markdown.cpp | 2 +- src/memberdef.cpp | 1 - src/objcache.cpp | 329 ----------------------------------------------------- src/objcache.h | 127 --------------------- src/util.cpp | 6 +- 10 files changed, 9 insertions(+), 470 deletions(-) delete mode 100644 src/objcache.cpp delete mode 100644 src/objcache.h diff --git a/qtools/qglobal.h b/qtools/qglobal.h index d37bdf2..0deef5d 100644 --- a/qtools/qglobal.h +++ b/qtools/qglobal.h @@ -507,7 +507,6 @@ Q_EXPORT bool qSysInfo( int *wordSize, bool *bigEndian ); #pragma warning(disable: 4244) #pragma warning(disable: 4275) #pragma warning(disable: 4514) -#pragma warning(disable: 4800) #pragma warning(disable: 4097) #pragma warning(disable: 4706) #elif defined(_CC_BOR_) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bed61a2..201b7c8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -262,7 +262,6 @@ add_library(_doxygen STATIC message.cpp msc.cpp namespacedef.cpp - objcache.cpp outputgen.cpp outputlist.cpp pagedef.cpp diff --git a/src/doxygen.cpp b/src/doxygen.cpp index af056f1..3fa6959 100644 --- a/src/doxygen.cpp +++ b/src/doxygen.cpp @@ -83,7 +83,6 @@ #include "sqlcode.h" #include "tclscanner.h" #include "code.h" -#include "objcache.h" #include "portable.h" #include "vhdljjparser.h" #include "vhdldocgen.h" diff --git a/src/doxygen.h b/src/doxygen.h index 635ac1d..f549261 100644 --- a/src/doxygen.h +++ b/src/doxygen.h @@ -34,7 +34,6 @@ class PageSDict; class PageDef; class SearchIndexIntf; class ParserManager; -class ObjCache; class Store; class QFileInfo; class BufStr; diff --git a/src/latexgen.cpp b/src/latexgen.cpp index 1780c36..dc8d2fe 100644 --- a/src/latexgen.cpp +++ b/src/latexgen.cpp @@ -80,12 +80,12 @@ void LatexCodeGenerator::codify(const char *str) { if (str) { - const char *p=str; - char c; + const signed char *p=(const signed char*)str; + signed char c; //char cs[5]; int spacesToNextTabStop; static int tabSize = Config_getInt(TAB_SIZE); - static char *result = NULL; + static signed char *result = NULL; static int lresult = 0; int i; while ((c=*p)) @@ -119,7 +119,7 @@ void LatexCodeGenerator::codify(const char *str) if (lresult < (i + 5)) \ { \ lresult += 512; \ - result = (char *)realloc(result, lresult); \ + result = (signed char *)realloc(result, lresult); \ } \ result[i++]=c; p++; \ if (c<0) /* multibyte utf-8 character */ \ @@ -151,7 +151,7 @@ void LatexCodeGenerator::codify(const char *str) result[i]=0; // add terminator //if (m_prettyCode) //{ - filterLatexString(m_t,result,FALSE,TRUE); + filterLatexString(m_t,(const char *)result,FALSE,TRUE); //} //else //{ diff --git a/src/markdown.cpp b/src/markdown.cpp index 86da735..caf77b5 100644 --- a/src/markdown.cpp +++ b/src/markdown.cpp @@ -2465,7 +2465,7 @@ static QCString detab(const QCString &s,int &refIndent) int minIndent=maxIndent; while (i -#include -#include -#include "objcache.h" -#if !defined(_OS_WIN32_) || defined(__MINGW32__) -#include -#endif - -//---------------------------------------------------------------------- - -ObjCache::ObjCache(unsigned int logSize) - : m_head(-1), m_tail(-1), //m_numEntries(0), - m_size(1<index); - moveToFront(hnode->index); - m_hits++; - } - else // object not in the cache. - { - void *lruObj=0; - if (m_freeCacheNodes!=-1) // cache not full -> add element to the cache - { - // remove element from free list - int index = m_freeCacheNodes; - m_freeCacheNodes = m_cache[index].next; - - // add to head of the list - if (m_tail==-1) - { - m_tail = index; - } - m_cache[index].prev = -1; - m_cache[index].next = m_head; - if (m_head!=-1) - { - m_cache[m_head].prev = index; - } - m_head = index; - m_count++; - } - else // cache full -> replace element in the cache - { - //printf("Cache full!\n"); - lruObj = m_cache[m_tail].obj; - hashRemove(lruObj); - moveToFront(m_tail); // m_tail indexes the emptied element, which becomes m_head - } - //printf("numEntries=%d size=%d\n",m_numEntries,m_size); - m_cache[m_head].obj = obj; - hnode = hashInsert(obj); - hnode->index = m_head; - *victim = lruObj; - m_misses++; - } - return m_head; -} - -void ObjCache::del(int index) -{ - assert(index!=-1); - assert(m_cache[index].obj!=0); - hashRemove(m_cache[index].obj); - moveToFront(index); - m_head = m_cache[index].next; - if (m_head==-1) - m_tail=-1; - else - m_cache[m_head].prev=-1; - m_cache[index].obj=0; - m_cache[index].prev=-1; - m_cache[index].next = m_freeCacheNodes; - m_freeCacheNodes = index; - m_count--; -} - -#ifdef CACHE_DEBUG -#define cache_debug_printf printf -void ObjCache::printLRU() -{ - cache_debug_printf("MRU->LRU: "); - int index = m_head; - while (index!=-1) - { - cache_debug_printf("%d=%p ",index,m_cache[index].obj); - index = m_cache[index].next; - } - cache_debug_printf("\n"); - - cache_debug_printf("LRU->MRU: "); - index = m_tail; - while (index!=-1) - { - cache_debug_printf("%d=%p ",index,m_cache[index].obj); - index = m_cache[index].prev; - } - cache_debug_printf("\n"); -} -#endif - -#ifdef CACHE_STATS -#define cache_stats_printf printf -void ObjCache::printStats() -{ - cache_stats_printf("ObjCache: hits=%d misses=%d hit ratio=%f\n",m_hits,m_misses,m_hits*100.0/(m_hits+m_misses)); -} -#endif - -void ObjCache::moveToFront(int index) -{ - int prev,next; - if (m_head!=index) - { - next = m_cache[index].next; - prev = m_cache[index].prev; - - // de-chain node at index - m_cache[prev].next = next; - if (next!=-1) m_cache[next].prev = prev; else m_tail = prev; - - // add to head - m_cache[index].prev = -1; - m_cache[index].next = m_head; - m_cache[m_head].prev = index; - m_head = index; - } -} - -unsigned int ObjCache::hash(void *addr) -{ - static bool isPtr64 = sizeof(addr)==8; - if (isPtr64) - { - uint64 key = (uint64)addr; - // Thomas Wang's 64 bit Mix Function - key += ~(key << 32); - key ^= (key >> 22); - key += ~(key << 13); - key ^= (key >> 8); - key += (key << 3); - key ^= (key >> 15); - key += ~(key << 27); - key ^= (key >> 31); - return (unsigned int)(key & (m_size-1)); - } - else - { - // Thomas Wang's 32 bit Mix Function - uintptr_t key = (uintptr_t)addr; - key += ~(key << 15); - key ^= (key >> 10); - key += (key << 3); - key ^= (key >> 6); - key += ~(key << 11); - key ^= (key >> 16); - return (unsigned int)(key & (m_size-1)); - } -} - -ObjCache::HashNode *ObjCache::hashFind(void *obj) -{ - HashNode *node = 0; - int index = m_hash[hash(obj)].head; - //printf("hashFind: obj=%p index=%d\n",obj,index); - while (index!=-1 && - m_hash[index].obj!=obj - ) // search for right object in the list - { - index = m_hash[index].nextHash; - } - // found the obj at index, so it is in the cache! - if (index!=-1) - { - node = &m_hash[index]; - } - return node; -} - -ObjCache::HashNode *ObjCache::hashInsert(void *obj) -{ - int index = hash(obj); - //printf("Inserting %p index=%d\n",obj,index); - - // remove element from empty list - int newElement = m_freeHashNodes; - assert(newElement!=-1); - m_freeHashNodes = m_hash[m_freeHashNodes].nextHash; - - if (m_hash[index].head!=-1) // hash collision -> goto end of the list - { - index = m_hash[index].head; - while (m_hash[index].nextHash!=-1) - { - index = m_hash[index].nextHash; - } - // add to end of the list - m_hash[index].nextHash = newElement; - } - else // first element in the hash list - { - m_hash[index].head = newElement; - } - // add to the end of the list - m_hash[newElement].nextHash = -1; - m_hash[newElement].obj = obj; - return &m_hash[newElement]; -} - -void ObjCache::hashRemove(void *obj) -{ - int index = hash(obj); - - // find element - int curIndex = m_hash[index].head; - int prevIndex=-1; - while (m_hash[curIndex].obj!=obj) - { - prevIndex = curIndex; - curIndex = m_hash[curIndex].nextHash; - } - - if (prevIndex==-1) // remove from start - { - m_hash[index].head = m_hash[curIndex].nextHash; - } - else // remove in the middle - { - m_hash[prevIndex].nextHash = m_hash[curIndex].nextHash; - } - - // add curIndex element to empty list - m_hash[curIndex].nextHash = m_freeHashNodes; - m_hash[curIndex].index = -1; - m_hash[curIndex].obj = 0; - m_freeHashNodes = curIndex; -} - -#ifdef CACHE_TEST -int main() -{ - int i; - struct obj - { - obj() : handle(-1) {} - int handle; - }; - obj *objs = new obj[100]; - ObjCache c(3); - for (i=0;i<32;i++) - { - int objId=(i%3)+(i>>2)*4; - printf("------- use(%d=%p)--------\n",objId,&objs[objId]); -#ifdef CACHE_DEBUG - c.printLRU(); -#endif - obj *victim=0; - if (objs[objId].handle==-1) - { - objs[objId].handle = c.add(&objs[objId],(void**)&victim); - if (victim) victim->handle=-1; - } - else - { - c.use(objs[objId].handle); - } - printf("i=%d objId=%d using %p victim=%p\n",i,objId,&objs[objId],victim); - } - for (i=0;i<100;i++) - { - if (objs[i].handle!=-1) - { - printf("------ del objId=%d handle=%d ------\n",i,objs[i].handle); - c.del(objs[i].handle); - objs[i].handle=-1; -#ifdef CACHE_DEBUG - c.printLRU(); -#endif - } - } - c.printStats(); - return 0; -} -#endif diff --git a/src/objcache.h b/src/objcache.h deleted file mode 100644 index 224b34b..0000000 --- a/src/objcache.h +++ /dev/null @@ -1,127 +0,0 @@ -/****************************************************************************** - * - * - * - * Copyright (C) 1997-2015 by Dimitri van Heesch. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation under the terms of the GNU General Public License is hereby - * granted. No representations are made about the suitability of this software - * for any purpose. It is provided "as is" without express or implied warranty. - * See the GNU General Public License for more details. - * - * Documents produced by Doxygen are derivative works derived from the - * input used in their production; they are not affected by this license. - * - */ - -#ifndef OBJCACHE_H -#define OBJCACHE_H - -//#define CACHE_TEST -//#define CACHE_DEBUG -#define CACHE_STATS - -/** @brief Cache for objects. - * - * This cache is used to decide which objects should remain in - * memory. It uses a least recently used policy (LRU) to decide - * which object should make room for a new object when the cache - * is full. An object should be added using add(), and then use() - * should be called when the object is used. - */ -class ObjCache -{ - private: - struct CacheNode - { - CacheNode() : next(-1), prev(-1), obj(0) {} - int next; - int prev; - void *obj; - }; - struct HashNode - { - HashNode() : head(-1), nextHash(-1), index(-1), obj(0) {} - int head; - int nextHash; - int index; - void *obj; - }; - - public: - /*! Creates the cache. The number of elements in the cache is 2 to - * the power of \a logSize. - */ - ObjCache(unsigned int logSize); - - /*! Deletes the cache and free all internal data-structures used. */ - ~ObjCache(); - - /*! Adds \a obj to the cache. When victim is not null, this object is - * removed from the cache to make room for \a obj. - * Returns a handle to the object, which can be used by the use() - * function, each time the object is used. - */ - int add(void *obj,void **victim); - - /*! Indicates that this object is used. This will move the object - * to the front of the internal LRU list to make sure it is removed last. - * The parameter \a handle is returned when called add(). - */ - void use(int handle) - { - if (handle==m_lastHandle) return; - m_lastHandle = handle; - m_hits++; - moveToFront(handle); - } - - /*! Removes the item identified by \a handle from the cache. - * @see add() - */ - void del(int handle); - - /*! Debug function. Prints the LRU list */ - void printLRU(); - /*! Print miss/hits statistics */ - void printStats(); - - /*! total size of the cache */ - int size() const { return m_size; } - - /*! number of elements in the cache */ - int count() const { return m_count; } - - int hits() const - { - return m_hits; - } - int misses() const - { - return m_misses; - } - - - private: - void moveToFront(int index); - unsigned int hash(void *addr); - HashNode *hashFind(void *obj); - HashNode *hashInsert(void *obj); - void hashRemove(void *obj); - - CacheNode *m_cache; - HashNode *m_hash; - int m_head; - int m_tail; - int m_size; - int m_count; - int m_freeHashNodes; - int m_freeCacheNodes; - int m_lastHandle; - int m_misses; - int m_hits; -}; - -#endif // OBJCACHE_H - diff --git a/src/util.cpp b/src/util.cpp index b7dc69d..28af27b 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -4849,8 +4849,8 @@ QCString escapeCharsInString(const char *name,bool allowDots,bool allowUnderscor static GrowBuf growBuf; growBuf.clear(); if (name==0) return ""; - char c; - const char *p=name; + signed char c; + const signed char *p=(const signed char*)name; while ((c=*p++)!=0) { switch(c) @@ -4890,7 +4890,7 @@ QCString escapeCharsInString(const char *name,bool allowDots,bool allowUnderscor bool doEscape = TRUE; if (allowUnicodeNames && uc <= 0xf7) { - const char* pt = p; + const signed char* pt = p; ids[ 0 ] = c; int l = 0; if ((uc&0xE0)==0xC0) -- cgit v0.12