summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Sander <oliver.sander@tu-dresden.de>2023-04-02 14:38:53 +0200
committerAlbert Astals Cid <tsdgeos@yahoo.es>2023-04-03 21:17:39 +0000
commit8354c73ea0516a9d4a4bdf68da5c5392498b286d (patch)
tree1ba60733c81db08fdae75ef4e5df41170a6b5a71
parent013ab299d7041691760fbf8626cb4125e6a5a459 (diff)
Make filterPSName return std::string
Rather than a pointer to GooString. This saves one memory allocation.
-rw-r--r--poppler/PSOutputDev.cc41
-rw-r--r--poppler/PSOutputDev.h2
2 files changed, 18 insertions, 25 deletions
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 23e3dcf0..80212e37 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -2772,32 +2772,27 @@ void PSOutputDev::setupType3Font(GfxFont *font, GooString *psName, Dict *parentR
// font object, and an object ID (font file object for
GooString *PSOutputDev::makePSFontName(GfxFont *font, const Ref *id)
{
- GooString *psName;
const GooString *s;
if ((s = font->getEmbeddedFontName())) {
- psName = filterPSName(s->toStr());
- if (fontNames.emplace(psName->toStr()).second) {
- return psName;
+ std::string psName = filterPSName(s->toStr());
+ if (fontNames.emplace(psName).second) {
+ return new GooString(std::move(psName));
}
- delete psName;
}
if (font->getName()) {
- psName = filterPSName(*font->getName());
- if (fontNames.emplace(psName->toStr()).second) {
- return psName;
+ std::string psName = filterPSName(*font->getName());
+ if (fontNames.emplace(psName).second) {
+ return new GooString(std::move(psName));
}
- delete psName;
}
- psName = GooString::format("FF{0:d}_{1:d}", id->num, id->gen).release();
+ GooString *psName = GooString::format("FF{0:d}_{1:d}", id->num, id->gen).release();
if ((s = font->getEmbeddedFontName())) {
- s = filterPSName(s->toStr());
- psName->append('_')->append(s);
- delete s;
+ std::string filteredName = filterPSName(s->toStr());
+ psName->append('_')->append(filteredName);
} else if (font->getName()) {
- s = filterPSName(*font->getName());
- psName->append('_')->append(s);
- delete s;
+ std::string filteredName = filterPSName(*font->getName());
+ psName->append('_')->append(filteredName);
}
fontNames.emplace(psName->toStr());
return psName;
@@ -7415,27 +7410,25 @@ void PSOutputDev::writePSName(const char *s)
}
}
-GooString *PSOutputDev::filterPSName(const std::string &name)
+std::string PSOutputDev::filterPSName(const std::string &name)
{
- GooString *name2;
- char buf[8];
-
- name2 = new GooString();
+ std::string name2;
// ghostscript chokes on names that begin with out-of-limits
// numbers, e.g., 1e4foo is handled correctly (as a name), but
// 1e999foo generates a limitcheck error
const char c0 = name[0];
if (c0 >= '0' && c0 <= '9') {
- name2->append('f');
+ name2 += 'f';
}
for (const char c : name) {
if (c <= (char)0x20 || c >= (char)0x7f || c == '(' || c == ')' || c == '<' || c == '>' || c == '[' || c == ']' || c == '{' || c == '}' || c == '/' || c == '%') {
+ char buf[8];
sprintf(buf, "#%02x", c & 0xff);
- name2->append(buf);
+ name2.append(buf);
} else {
- name2->append(c);
+ name2 += c;
}
}
return name2;
diff --git a/poppler/PSOutputDev.h b/poppler/PSOutputDev.h
index dad0a384..1b6257c9 100644
--- a/poppler/PSOutputDev.h
+++ b/poppler/PSOutputDev.h
@@ -401,7 +401,7 @@ private:
void opiTransform(GfxState *state, double x0, double y0, double *x1, double *y1);
#endif
void cvtFunction(const Function *func, bool invertPSFunction = false);
- GooString *filterPSName(const std::string &name);
+ static std::string filterPSName(const std::string &name);
// Write the document-level setup.
void writeDocSetup(Catalog *catalog, const std::vector<int> &pageList, bool duplexA);