Skip to content

Commit 9a0a0a6

Browse files
committed
Refactoring: replace GrowBuf with normal QCString.
Rationale: - not really beneficial to use a custom type anymore. - Using same type as return type gives the compiler more options for return value optimization (RVO).
1 parent 9637460 commit 9a0a0a6

14 files changed

+268
-409
lines changed

src/cite.cpp

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "debug.h"
2525
#include "fileinfo.h"
2626
#include "dir.h"
27-
#include "growbuf.h"
2827
#include "entry.h"
2928
#include "commentscan.h"
3029
#include "linkedmap.h"
@@ -232,17 +231,17 @@ void CitationManager::insertCrossReferencesForBibFile(const QCString &bibFile)
232231
}
233232
}
234233

235-
const std::string g_formulaMarker = "CITE_FORMULA_";
234+
static const std::string g_formulaMarker = "CITE_FORMULA_";
236235

237236
QCString CitationManager::getFormulas(const QCString &s)
238237
{
239238
if (s.isEmpty()) return s;
240-
GrowBuf growBuf;
241-
GrowBuf formulaBuf;
239+
QCString result;
240+
result.reserve(s.length()+32);
241+
QCString formula;
242+
formula.reserve(256);
242243
bool insideFormula = false;
243244
int citeFormulaCnt = 1;
244-
const size_t tmpLen = 30;
245-
char tmp[tmpLen];
246245
const char *ps=s.data();
247246
char c = 0;
248247
while ((c=*ps++))
@@ -252,32 +251,34 @@ QCString CitationManager::getFormulas(const QCString &s)
252251
switch (c)
253252
{
254253
case '\\':
255-
formulaBuf.addChar(c);
254+
formula+=c;
256255
c = *ps++;
257-
formulaBuf.addChar(c);
256+
formula+=c;
258257
break;
259258
case '\n':
260-
formulaBuf.addChar(c);
261-
formulaBuf.addChar(0);
262-
growBuf.addChar('$');
263-
growBuf.addStr(formulaBuf.get());
259+
formula+=c;
260+
result+='$';
261+
result+=formula;
264262
insideFormula = false;
265-
formulaBuf.clear();
263+
formula.clear();
266264
break;
267265
case '$':
268-
qsnprintf(tmp,tmpLen,"%s%06d",g_formulaMarker.c_str(),citeFormulaCnt);
269-
formulaBuf.addChar(0);
270-
p->formulaCite.emplace(citeFormulaCnt,std::string("\\f$") + formulaBuf.get() + "\\f$");
271-
citeFormulaCnt++;
272-
// need { and } due to the capitalization rules of bibtex.
273-
growBuf.addChar('{');
274-
growBuf.addStr(tmp);
275-
growBuf.addChar('}');
276-
insideFormula = false;
277-
formulaBuf.clear();
266+
{
267+
const size_t idLen = 30;
268+
char id[idLen];
269+
qsnprintf(id,idLen,"%s%06d",g_formulaMarker.c_str(),citeFormulaCnt);
270+
p->formulaCite.emplace(citeFormulaCnt,std::string("\\f$") + formula.str() + "\\f$");
271+
citeFormulaCnt++;
272+
// need { and } due to the capitalization rules of bibtex.
273+
result+='{';
274+
result+=id;
275+
result+='}';
276+
insideFormula = false;
277+
formula.clear();
278+
}
278279
break;
279280
default:
280-
formulaBuf.addChar(c);
281+
formula+=c;
281282
break;
282283
}
283284
}
@@ -286,27 +287,25 @@ QCString CitationManager::getFormulas(const QCString &s)
286287
switch (c)
287288
{
288289
case '\\':
289-
growBuf.addChar(c);
290+
result+=c;
290291
c = *ps++;
291-
growBuf.addChar(c);
292+
result+=c;
292293
break;
293294
case '$':
294295
insideFormula = true;
295296
break;
296297
default:
297-
growBuf.addChar(c);
298+
result+=c;
298299
break;
299300
}
300301
}
301302
}
302303
if (insideFormula)
303304
{
304-
formulaBuf.addChar(0);
305-
growBuf.addStr(formulaBuf.get());
306-
formulaBuf.clear();
305+
result+=formula;
306+
formula.clear();
307307
}
308-
growBuf.addChar(0);
309-
return growBuf.get();
308+
return result;
310309
}
311310

312311
QCString CitationManager::replaceFormulas(const QCString &s)

src/clangparser.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "doxygen.h"
1919
#include "util.h"
2020
#include "config.h"
21-
#include "growbuf.h"
2221
#include "membername.h"
2322
#include "filename.h"
2423
#include "tooltip.h"

src/datetime.cpp

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "portable.h"
2626
#include "language.h"
2727
#include "message.h"
28-
#include "growbuf.h"
2928

3029
std::tm getCurrentDateTime()
3130
{
@@ -179,7 +178,13 @@ QCString formatDateTime(const QCString &format,const std::tm &dt,int &formatUsed
179178
auto getMonth = [](const std::tm &dat) { return dat.tm_mon+1; };
180179
auto getDay = [](const std::tm &dat) { return dat.tm_mday; };
181180
auto getDayOfWeek = [](const std::tm &dat) { return (dat.tm_wday+6)%7+1; };
182-
GrowBuf growBuf;
181+
QCString result;
182+
result.reserve(256);
183+
auto addInt = [&result](const char *fmt,int value) {
184+
char tmp[50];
185+
qsnprintf(tmp,50,fmt,value);
186+
result+=tmp;
187+
};
183188
char c = 0;
184189
const char *p = format.data();
185190
const char *fmt_zero = "%02d";
@@ -196,36 +201,35 @@ QCString formatDateTime(const QCString &format,const std::tm &dt,int &formatUsed
196201
if (nc=='-') nc=*++p; // skip over -
197202
switch (nc)
198203
{
199-
case '%': growBuf.addChar('%'); break;
200-
case 'y': growBuf.addInt(fmt_selected,getYear(dt)%100); formatUsed|=SF_Date; break;
201-
case 'Y': growBuf.addInt("%d",getYear(dt)); formatUsed|=SF_Date; break;
202-
case 'm': growBuf.addInt(fmt_selected,getMonth(dt)); formatUsed|=SF_Date; break;
203-
case 'b': growBuf.addStr(theTranslator->trMonth(getMonth(dt),false,false)); formatUsed|=SF_Date; break;
204-
case 'B': growBuf.addStr(theTranslator->trMonth(getMonth(dt),false,true)); formatUsed|=SF_Date; break;
205-
case 'd': growBuf.addInt(fmt_selected,getDay(dt)); formatUsed|=SF_Date; break;
206-
case 'u': growBuf.addInt("%d",getDayOfWeek(dt)); /* Monday = 1 ... Sunday = 7 */ formatUsed|=SF_Date; break;
207-
case 'w': growBuf.addInt("%d",getDayOfWeek(dt)%7); /* Sunday = 0 ... Saturday = 6 */ formatUsed|=SF_Date; break;
208-
case 'a': growBuf.addStr(theTranslator->trDayOfWeek(getDayOfWeek(dt),false,false)); formatUsed|=SF_Date; break;
209-
case 'A': growBuf.addStr(theTranslator->trDayOfWeek(getDayOfWeek(dt),false,true)); formatUsed|=SF_Date; break;
210-
case 'H': growBuf.addInt(fmt_selected,dt.tm_hour); formatUsed|=SF_Time; break;
211-
case 'I': growBuf.addInt(fmt_selected,dt.tm_hour%12); formatUsed|=SF_Time; break;
212-
case 'p': growBuf.addStr(theTranslator->trDayPeriod(dt.tm_hour>=12)); formatUsed|=SF_Time; break;
213-
case 'M': growBuf.addInt(fmt_selected,dt.tm_min); formatUsed|=SF_Time; break;
214-
case 'S': growBuf.addInt(fmt_selected,dt.tm_sec); formatUsed|=SF_Seconds; break;
204+
case '%': result+='%'; break;
205+
case 'y': addInt(fmt_selected,getYear(dt)%100); formatUsed|=SF_Date; break;
206+
case 'Y': addInt("%d",getYear(dt)); formatUsed|=SF_Date; break;
207+
case 'm': addInt(fmt_selected,getMonth(dt)); formatUsed|=SF_Date; break;
208+
case 'b': result+=theTranslator->trMonth(getMonth(dt),false,false); formatUsed|=SF_Date; break;
209+
case 'B': result+=theTranslator->trMonth(getMonth(dt),false,true); formatUsed|=SF_Date; break;
210+
case 'd': addInt(fmt_selected,getDay(dt)); formatUsed|=SF_Date; break;
211+
case 'u': addInt("%d",getDayOfWeek(dt)); /* Monday = 1 ... Sunday = 7 */ formatUsed|=SF_Date; break;
212+
case 'w': addInt("%d",getDayOfWeek(dt)%7); /* Sunday = 0 ... Saturday = 6 */ formatUsed|=SF_Date; break;
213+
case 'a': result+=theTranslator->trDayOfWeek(getDayOfWeek(dt),false,false); formatUsed|=SF_Date; break;
214+
case 'A': result+=theTranslator->trDayOfWeek(getDayOfWeek(dt),false,true); formatUsed|=SF_Date; break;
215+
case 'H': addInt(fmt_selected,dt.tm_hour); formatUsed|=SF_Time; break;
216+
case 'I': addInt(fmt_selected,dt.tm_hour%12); formatUsed|=SF_Time; break;
217+
case 'p': result+=theTranslator->trDayPeriod(dt.tm_hour>=12); formatUsed|=SF_Time; break;
218+
case 'M': addInt(fmt_selected,dt.tm_min); formatUsed|=SF_Time; break;
219+
case 'S': addInt(fmt_selected,dt.tm_sec); formatUsed|=SF_Seconds; break;
215220
default:
216-
growBuf.addChar(c);
217-
if (*(p-1)=='-') growBuf.addChar('-');
218-
growBuf.addChar(nc);
221+
result+=c;
222+
if (*(p-1)=='-') result+='-';
223+
result+=nc;
219224
break;
220225
}
221226
p++;
222227
break;
223228
default:
224-
growBuf.addChar(c);
229+
result+=c;
225230
break;
226231
}
227232
}
228-
growBuf.addChar(0);
229-
return growBuf.get();
233+
return result;
230234
}
231235

src/diagram.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "indexlist.h"
2929
#include "classlist.h"
3030
#include "textstream.h"
31-
#include "growbuf.h"
3231
#include "dir.h"
3332

3433
//-----------------------------------------------------------------------------
@@ -193,20 +192,20 @@ static uint32_t virtToMask(Specifier p)
193192
static QCString convertToPSString(const QCString &s)
194193
{
195194
if (s.isEmpty()) return s;
196-
GrowBuf growBuf;
195+
QCString result;
196+
result.reserve(s.length()+8);
197197
const char *p=s.data();
198198
char c=0;
199199
while ((c=*p++))
200200
{
201201
switch (c)
202202
{
203-
case '(': growBuf.addStr("\\("); break;
204-
case ')': growBuf.addStr("\\)"); break;
205-
default: growBuf.addChar(c); break;
203+
case '(': result+="\\("; break;
204+
case ')': result+="\\)"; break;
205+
default: result+=c; break;
206206
}
207207
}
208-
growBuf.addChar(0);
209-
return growBuf.get();
208+
return result;
210209
}
211210

212211
// pre: dil is not empty

src/docbookgen.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
#include "dirdef.h"
5151
#include "section.h"
5252
#include "dir.h"
53-
#include "growbuf.h"
5453
#include "outputlist.h"
5554
#include "moduledef.h"
5655

@@ -1485,7 +1484,8 @@ static constexpr auto hex="0123456789ABCDEF";
14851484
QCString convertToDocBook(const QCString &s, const bool retainNewline)
14861485
{
14871486
if (s.isEmpty()) return s;
1488-
GrowBuf growBuf;
1487+
QCString result;
1488+
result.reserve(s.length()+32);
14891489
const char *p = s.data();
14901490
const char *q = nullptr;
14911491
int cnt = 0;
@@ -1494,9 +1494,12 @@ QCString convertToDocBook(const QCString &s, const bool retainNewline)
14941494
{
14951495
switch (c)
14961496
{
1497-
case '\n': if (retainNewline) growBuf.addStr("<literallayout>&#160;&#xa;</literallayout>"); growBuf.addChar(c); break;
1498-
case '<': growBuf.addStr("&lt;"); break;
1499-
case '>': growBuf.addStr("&gt;"); break;
1497+
case '\n':
1498+
if (retainNewline) result+="<literallayout>&#160;&#xa;</literallayout>";
1499+
result+=c;
1500+
break;
1501+
case '<': result+="&lt;"; break;
1502+
case '>': result+="&gt;"; break;
15001503
case '&': // possibility to have a special symbol
15011504
q = p;
15021505
cnt = 2; // we have to count & and ; as well
@@ -1512,37 +1515,36 @@ QCString convertToDocBook(const QCString &s, const bool retainNewline)
15121515
if (res == HtmlEntityMapper::Sym_Unknown)
15131516
{
15141517
p++;
1515-
growBuf.addStr("&amp;");
1518+
result+="&amp;";
15161519
}
15171520
else
15181521
{
1519-
growBuf.addStr(HtmlEntityMapper::instance().docbook(res));
1522+
result+=HtmlEntityMapper::instance().docbook(res);
15201523
q++;
15211524
p = q;
15221525
}
15231526
}
15241527
else
15251528
{
1526-
growBuf.addStr("&amp;");
1529+
result+="&amp;";
15271530
}
15281531
break;
1529-
case '\'': growBuf.addStr("&apos;"); break;
1530-
case '"': growBuf.addStr("&quot;"); break;
1532+
case '\'': result+="&apos;"; break;
1533+
case '"': result+="&quot;"; break;
15311534
case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
15321535
case 11: case 12: case 14: case 15: case 16: case 17: case 18:
15331536
case 19: case 20: case 21: case 22: case 23: case 24: case 25: case 26:
15341537
case 27: case 28: case 29: case 30: case 31:
1535-
growBuf.addStr("&#x24");
1536-
growBuf.addChar(hex[static_cast<uint8_t>(c)>>4]);
1537-
growBuf.addChar(hex[static_cast<uint8_t>(c)&0xF]);
1538-
growBuf.addChar(';');
1538+
result+="&#x24";
1539+
result+=hex[static_cast<uint8_t>(c)>>4];
1540+
result+=hex[static_cast<uint8_t>(c)&0xF];
1541+
result+=';';
15391542
break;
15401543
default:
1541-
growBuf.addChar(c);
1544+
result+=c;
15421545
break;
15431546
}
15441547
}
1545-
growBuf.addChar(0);
1546-
return growBuf.get();
1548+
return result;
15471549
}
15481550

src/docbookvisitor.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "htmlentity.h"
3232
#include "emoji.h"
3333
#include "plantuml.h"
34-
#include "growbuf.h"
3534
#include "fileinfo.h"
3635
#include "portable.h"
3736
#include "codefragment.h"
@@ -52,20 +51,19 @@
5251
static QCString filterId(const QCString &s)
5352
{
5453
if (s.isEmpty()) return s;
55-
GrowBuf growBuf;
56-
growBuf.clear();
54+
QCString result;
55+
result.reserve(s.length()+8);
5756
const char *p=s.data();
5857
char c=0;
5958
while ((c=*p++))
6059
{
6160
switch (c)
6261
{
63-
case ':': growBuf.addStr("_1"); break;
64-
default: growBuf.addChar(c); break;
62+
case ':': result+="_1"; break;
63+
default: result+=c; break;
6564
}
6665
}
67-
growBuf.addChar(0);
68-
return growBuf.get();
66+
return result;
6967
}
7068

7169
static bool supportedHtmlAttribute(const QCString &name)

0 commit comments

Comments
 (0)