summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDimitri van Heesch <dimitri@stack.nl>2014-10-23 18:33:19 (GMT)
committerDimitri van Heesch <dimitri@stack.nl>2014-10-23 18:33:19 (GMT)
commit43edc14cd357dcb070402bccc5030507570c22a4 (patch)
tree05c76a0026b6d1fabe1c3967b041e38b9550f9f7 /src
parent151876a8321204bd2ec08ec6c4de38ba9fb2d034 (diff)
downloadDoxygen-43edc14cd357dcb070402bccc5030507570c22a4.zip
Doxygen-43edc14cd357dcb070402bccc5030507570c22a4.tar.gz
Doxygen-43edc14cd357dcb070402bccc5030507570c22a4.tar.bz2
Introduce new optimized string implementation (attempt 2)
Diffstat (limited to 'src')
-rw-r--r--src/definition.cpp12
-rw-r--r--src/dirdef.h2
-rw-r--r--src/filedef.h2
-rw-r--r--src/htmlgen.cpp43
-rw-r--r--src/membergroup.h2
-rw-r--r--src/util.cpp46
-rw-r--r--src/util.h2
-rw-r--r--src/vhdldocgen.cpp5
-rw-r--r--src/vhdljjparser.cpp6
9 files changed, 65 insertions, 55 deletions
diff --git a/src/definition.cpp b/src/definition.cpp
index 3c11916..4a8c65d 100644
--- a/src/definition.cpp
+++ b/src/definition.cpp
@@ -890,16 +890,17 @@ QCString Definition::getSourceFileBase() const
QCString Definition::getSourceAnchor() const
{
- QCString anchorStr;
+ const int maxAnchorStrLen = 20;
+ char anchorStr[maxAnchorStrLen];
if (m_impl->body && m_impl->body->startLine!=-1)
{
if (Htags::useHtags)
{
- anchorStr.sprintf("L%d",m_impl->body->startLine);
+ snprintf(anchorStr,maxAnchorStrLen,"L%d",m_impl->body->startLine);
}
else
{
- anchorStr.sprintf("l%05d",m_impl->body->startLine);
+ snprintf(anchorStr,maxAnchorStrLen,"l%05d",m_impl->body->startLine);
}
}
return anchorStr;
@@ -1163,8 +1164,9 @@ void Definition::_writeSourceRefList(OutputList &ol,const char *scopeName,
{
ol.disable(OutputGenerator::Latex);
}
- QCString lineStr,anchorStr;
- anchorStr.sprintf("l%05d",md->getStartBodyLine());
+ const int maxLineNrStr = 10;
+ char anchorStr[maxLineNrStr];
+ snprintf(anchorStr,maxLineNrStr,"l%05d",md->getStartBodyLine());
//printf("Write object link to %s\n",md->getBodyDef()->getSourceFileBase().data());
ol.writeObjectLink(0,md->getBodyDef()->getSourceFileBase(),anchorStr,name);
ol.popGeneratorState();
diff --git a/src/dirdef.h b/src/dirdef.h
index 1a9f40c..9a8a5ad 100644
--- a/src/dirdef.h
+++ b/src/dirdef.h
@@ -54,7 +54,7 @@ class DirDef : public Definition
bool isLinkableInProject() const;
bool isLinkable() const;
QCString displayName(bool=TRUE) const { return m_dispName; }
- QCString shortName() const { return m_shortName; }
+ const QCString &shortName() const { return m_shortName; }
void addSubDir(DirDef *subdir);
FileList * getFiles() const { return m_fileList; }
void addFile(FileDef *fd);
diff --git a/src/filedef.h b/src/filedef.h
index 8cd5703..33eae35 100644
--- a/src/filedef.h
+++ b/src/filedef.h
@@ -96,7 +96,7 @@ class FileDef : public Definition
QCString absFilePath() const { return m_filePath; }
/*! Returns the name as it is used in the documentation */
- QCString docName() const { return m_docname; }
+ const QCString &docName() const { return m_docname; }
/*! Returns TRUE if this file is a source file. */
bool isSource() const { return m_isSource; }
diff --git a/src/htmlgen.cpp b/src/htmlgen.cpp
index 62ae1c7..b459446 100644
--- a/src/htmlgen.cpp
+++ b/src/htmlgen.cpp
@@ -912,40 +912,6 @@ static void writeServerSearchBox(FTextStream &t,const char *relPath,bool highlig
//------------------------------------------------------------------------
-/// substitute all occurrences of \a src in \a s by \a dst
-QCString substitute(const char *s,const char *src,const char *dst)
-{
- if (s==0 || src==0) return s;
- const char *p, *q;
- int srcLen = qstrlen(src);
- int dstLen = dst ? qstrlen(dst) : 0;
- int resLen;
- if (srcLen!=dstLen)
- {
- int count;
- for (count=0, p=s; (q=strstr(p,src))!=0; p=q+srcLen) count++;
- resLen = (int)(p-s)+qstrlen(p)+count*(dstLen-srcLen);
- }
- else // result has same size as s
- {
- resLen = qstrlen(s);
- }
- QCString result(resLen+1);
- char *r;
- for (r=result.data(), p=s; (q=strstr(p,src))!=0; p=q+srcLen)
- {
- int l = (int)(q-p);
- memcpy(r,p,l);
- r+=l;
- if (dst) memcpy(r,dst,dstLen);
- r+=dstLen;
- }
- qstrcpy(r,p);
- //printf("substitute(%s,%s,%s)->%s\n",s,src,dst,result.data());
- return result;
-}
-//----------------------------------------------------------------------
-
/// Clear a text block \a s from \a begin to \a end markers
QCString clearBlock(const char *s,const char *begin,const char *end)
{
@@ -989,6 +955,7 @@ QCString clearBlock(const char *s,const char *begin,const char *end)
QCString selectBlock(const QCString& s,const QCString &name,bool enable)
{
+ // TODO: this is an expensive function that is called a lot -> optimize it
const QCString begin = "<!--BEGIN " + name + "-->";
const QCString end = "<!--END " + name + "-->";
const QCString nobegin = "<!--BEGIN !" + name + "-->";
@@ -1341,9 +1308,11 @@ void HtmlCodeGenerator::writeLineNumber(const char *ref,const char *filename,
const char *anchor,int l)
{
if (!m_streamSet) return;
- QCString lineNumber,lineAnchor;
- lineNumber.sprintf("%5d",l);
- lineAnchor.sprintf("l%05d",l);
+ const int maxLineNrStr = 10;
+ char lineNumber[maxLineNrStr];
+ char lineAnchor[maxLineNrStr];
+ snprintf(lineNumber,maxLineNrStr,"%5d",l);
+ snprintf(lineAnchor,maxLineNrStr,"l%05d",l);
m_t << "<div class=\"line\">";
m_t << "<a name=\"" << lineAnchor << "\"></a><span class=\"lineno\">";
diff --git a/src/membergroup.h b/src/membergroup.h
index e3f6c0f..daf8ccb 100644
--- a/src/membergroup.h
+++ b/src/membergroup.h
@@ -63,7 +63,7 @@ class MemberGroup
MemberListType lt,
ClassDef *inheritedFrom,const QCString &inheritId);
- QCString documentation() const { return doc; }
+ const QCString &documentation() const { return doc; }
bool allMembersInSameSection() const { return inSameSection; }
void addToDeclarationSection();
int countDecMembers(GroupDef *gd=0);
diff --git a/src/util.cpp b/src/util.cpp
index b313b86..666fd04 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -264,8 +264,9 @@ void writePageRef(OutputDocInterface &od,const char *cn,const char *mn)
*/
QCString generateMarker(int id)
{
- QCString result;
- result.sprintf("@%d",id);
+ const int maxMarkerStrLen = 20;
+ char result[maxMarkerStrLen];
+ snprintf(result,maxMarkerStrLen,"@%d",id);
return result;
}
@@ -4913,8 +4914,10 @@ FileDef *findFileDef(const FileNameDict *fnDict,const char *n,bool &ambig)
ambig=FALSE;
if (n==0) return 0;
- QCString key;
- key.sprintf("%p:",fnDict);
+ const int maxAddrSize = 20;
+ char addr[maxAddrSize];
+ snprintf(addr,maxAddrSize,"%p:",fnDict);
+ QCString key = addr;
key+=n;
g_findFileDefCache.setAutoDelete(TRUE);
@@ -5030,6 +5033,41 @@ QCString showFileDefMatches(const FileNameDict *fnDict,const char *n)
//----------------------------------------------------------------------
+/// substitute all occurrences of \a src in \a s by \a dst
+QCString substitute(const QCString &s,const QCString &src,const QCString &dst)
+{
+ if (s.isEmpty() || src.isEmpty()) return s;
+ const char *p, *q;
+ int srcLen = src.length();
+ int dstLen = dst.length();
+ int resLen;
+ if (srcLen!=dstLen)
+ {
+ int count;
+ for (count=0, p=s.data(); (q=strstr(p,src))!=0; p=q+srcLen) count++;
+ resLen = s.length()+count*(dstLen-srcLen);
+ }
+ else // result has same size as s
+ {
+ resLen = s.length();
+ }
+ QCString result(resLen+1);
+ char *r;
+ for (r=result.data(), p=s; (q=strstr(p,src))!=0; p=q+srcLen)
+ {
+ int l = (int)(q-p);
+ memcpy(r,p,l);
+ r+=l;
+ if (dst) memcpy(r,dst,dstLen);
+ r+=dstLen;
+ }
+ qstrcpy(r,p);
+ //printf("substitute(%s,%s,%s)->%s\n",s,src,dst,result.data());
+ return result;
+}
+
+//----------------------------------------------------------------------
+
QCString substituteKeywords(const QCString &s,const char *title,
const char *projName,const char *projNum,const char *projBrief)
{
diff --git a/src/util.h b/src/util.h
index 2fc71ce..07744ca 100644
--- a/src/util.h
+++ b/src/util.h
@@ -192,7 +192,7 @@ void mergeArguments(ArgumentList *,ArgumentList *,bool forceNameOverwrite=FALSE)
QCString substituteClassNames(const QCString &s);
-QCString substitute(const char *s,const char *src,const char *dst);
+QCString substitute(const QCString &s,const QCString &src,const QCString &dst);
QCString clearBlock(const char *s,const char *begin,const char *end);
diff --git a/src/vhdldocgen.cpp b/src/vhdldocgen.cpp
index ad95fd1..50127f8 100644
--- a/src/vhdldocgen.cpp
+++ b/src/vhdldocgen.cpp
@@ -1445,7 +1445,7 @@ bool VhdlDocGen::isNumber(const QCString& s)
void VhdlDocGen::formatString(const QCString &s, OutputList& ol,const MemberDef* mdef)
{
QCString qcs = s;
- QCString temp(qcs.length());
+ QCString temp;
qcs.stripPrefix(":");
qcs.stripPrefix("is");
qcs.stripPrefix("IS");
@@ -1464,7 +1464,7 @@ void VhdlDocGen::formatString(const QCString &s, OutputList& ol,const MemberDef*
if (j>0) b=qcs[j-1];
if (c=='"' || c==',' || c=='\''|| c=='(' || c==')' || c==':' || c=='[' || c==']' ) // || (c==':' && b!='=')) // || (c=='=' && b!='>'))
{
- if (temp.at(index-1) != ' ')
+ if (temp.length()>=index && temp.at(index-1) != ' ')
{
temp+=" ";
}
@@ -2322,6 +2322,7 @@ void VhdlDocGen::writePlainVHDLDeclarations(
{
SDict<QCString> pack(1009);
+ pack.setAutoDelete(TRUE);
bool first=TRUE;
MemberDef *md;
diff --git a/src/vhdljjparser.cpp b/src/vhdljjparser.cpp
index f31c9fb..d79c260 100644
--- a/src/vhdljjparser.cpp
+++ b/src/vhdljjparser.cpp
@@ -92,7 +92,7 @@ int VhdlParser::levelCounter;
static QList<VhdlConfNode> configL;
-struct
+static struct
{
QCString doc;
bool brief;
@@ -217,7 +217,7 @@ void VHDLLanguageScanner::parseInput(const char *fileName,const char *fileBuf,En
VhdlParser::current=new Entry();
VhdlParser::initEntry(VhdlParser::current);
groupEnterFile(fileName,yyLineNr);
- lineParse=new int[200];
+ lineParse=new int[200]; // Dimitri: dangerous constant: should be bigger than largest token id in VhdlParserConstants.h
VhdlParserIF::parseVhdlfile(fileBuf,inLine);
delete VhdlParser::current;
@@ -226,7 +226,7 @@ void VHDLLanguageScanner::parseInput(const char *fileName,const char *fileBuf,En
if (!inLine)
VhdlParser::mapLibPackage(root);
- delete lineParse;
+ delete[] lineParse;
yyFileName.resize(0);
libUse.clear();
VhdlDocGen::resetCodeVhdlParserState();