[poppler] poppler/GlobalParams.cc poppler/GlobalParams.h poppler/UnicodeMap.cc poppler/UnicodeMap.h

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jan 3 15:00:39 UTC 2020


 poppler/GlobalParams.cc |   14 +++++++-------
 poppler/GlobalParams.h  |    2 +-
 poppler/UnicodeMap.cc   |   18 ++++++++----------
 poppler/UnicodeMap.h    |   11 ++++++-----
 4 files changed, 22 insertions(+), 23 deletions(-)

New commits:
commit 4f16f53e2b2fc0b83bad9ffcb0c869200f06a406
Author: Albert Astals Cid <aacid at kde.org>
Date:   Fri Jan 3 14:11:01 2020 +0100

    Make UnicodeMap::encodingName be a std::string

diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index bbc2e668..71824bc2 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -428,17 +428,17 @@ GlobalParams::GlobalParams(const char *customPopplerDataDir)
   // set up the residentUnicodeMaps table
   residentUnicodeMaps.reserve(6);
   UnicodeMap map = {"Latin1", false, latin1UnicodeMapRanges, latin1UnicodeMapLen};
-  residentUnicodeMaps.emplace(map.getEncodingName()->toStr(), std::move(map));
+  residentUnicodeMaps.emplace(map.getEncodingName(), std::move(map));
   map = {"ASCII7", false, ascii7UnicodeMapRanges, ascii7UnicodeMapLen};
-  residentUnicodeMaps.emplace(map.getEncodingName()->toStr(), std::move(map));
+  residentUnicodeMaps.emplace(map.getEncodingName(), std::move(map));
   map = {"Symbol", false, symbolUnicodeMapRanges, symbolUnicodeMapLen};
-  residentUnicodeMaps.emplace(map.getEncodingName()->toStr(), std::move(map));
+  residentUnicodeMaps.emplace(map.getEncodingName(), std::move(map));
   map = {"ZapfDingbats", false, zapfDingbatsUnicodeMapRanges, zapfDingbatsUnicodeMapLen};
-  residentUnicodeMaps.emplace(map.getEncodingName()->toStr(), std::move(map));
+  residentUnicodeMaps.emplace(map.getEncodingName(), std::move(map));
   map = {"UTF-8", true, &mapUTF8};
-  residentUnicodeMaps.emplace(map.getEncodingName()->toStr(), std::move(map));
+  residentUnicodeMaps.emplace(map.getEncodingName(), std::move(map));
   map = {"UTF-16", true, &mapUTF16};
-  residentUnicodeMaps.emplace(map.getEncodingName()->toStr(), std::move(map));
+  residentUnicodeMaps.emplace(map.getEncodingName(), std::move(map));
 
   scanEncodingDirs();
 }
@@ -1164,7 +1164,7 @@ CharCodeToUnicode *GlobalParams::getCIDToUnicode(const GooString *collection) {
   return ctu;
 }
 
-UnicodeMap *GlobalParams::getUnicodeMap(GooString *encodingName) {
+UnicodeMap *GlobalParams::getUnicodeMap(const GooString *encodingName) {
   UnicodeMap *map;
 
   if (!(map = getResidentUnicodeMap(encodingName))) {
diff --git a/poppler/GlobalParams.h b/poppler/GlobalParams.h
index 795afcf5..2e72982a 100644
--- a/poppler/GlobalParams.h
+++ b/poppler/GlobalParams.h
@@ -134,7 +134,7 @@ public:
   bool getErrQuiet();
 
   CharCodeToUnicode *getCIDToUnicode(const GooString *collection);
-  UnicodeMap *getUnicodeMap(GooString *encodingName);
+  UnicodeMap *getUnicodeMap(const GooString *encodingName);
   CMap *getCMap(const GooString *collection, const GooString *cMapName, Stream *stream = nullptr);
   UnicodeMap *getTextEncoding();
 
diff --git a/poppler/UnicodeMap.cc b/poppler/UnicodeMap.cc
index de531166..377c9ac0 100644
--- a/poppler/UnicodeMap.cc
+++ b/poppler/UnicodeMap.cc
@@ -50,7 +50,7 @@ struct UnicodeMapExt {
 
 //------------------------------------------------------------------------
 
-UnicodeMap *UnicodeMap::parse(GooString *encodingNameA) {
+UnicodeMap *UnicodeMap::parse(const GooString *encodingNameA) {
   FILE *f;
   UnicodeMap *map;
   UnicodeMapRange *range;
@@ -68,7 +68,7 @@ UnicodeMap *UnicodeMap::parse(GooString *encodingNameA) {
     return nullptr;
   }
 
-  map = new UnicodeMap(encodingNameA->copy());
+  map = new UnicodeMap(encodingNameA->toStr());
 
   size = 8;
   UnicodeMapRange *customRanges = (UnicodeMapRange *)gmallocn(size, sizeof(UnicodeMapRange));
@@ -129,7 +129,7 @@ UnicodeMap *UnicodeMap::parse(GooString *encodingNameA) {
   return map;
 }
 
-UnicodeMap::UnicodeMap(GooString *encodingNameA) {
+UnicodeMap::UnicodeMap(const std::string &encodingNameA) {
   encodingName = encodingNameA;
   unicodeOut = false;
   kind = unicodeMapUser;
@@ -142,7 +142,7 @@ UnicodeMap::UnicodeMap(GooString *encodingNameA) {
 
 UnicodeMap::UnicodeMap(const char *encodingNameA, bool unicodeOutA,
 		       const UnicodeMapRange *rangesA, int lenA) {
-  encodingName = new GooString(encodingNameA);
+  encodingName = encodingNameA;
   unicodeOut = unicodeOutA;
   kind = unicodeMapResident;
   ranges = rangesA;
@@ -154,7 +154,7 @@ UnicodeMap::UnicodeMap(const char *encodingNameA, bool unicodeOutA,
 
 UnicodeMap::UnicodeMap(const char *encodingNameA, bool unicodeOutA,
 		       UnicodeMapFunc funcA) {
-  encodingName = new GooString(encodingNameA);
+  encodingName = encodingNameA;
   unicodeOut = unicodeOutA;
   kind = unicodeMapFunc;
   func = funcA;
@@ -164,7 +164,6 @@ UnicodeMap::UnicodeMap(const char *encodingNameA, bool unicodeOutA,
 }
 
 UnicodeMap::~UnicodeMap() {
-  delete encodingName;
   if (kind == unicodeMapUser && ranges) {
     gfree(const_cast<UnicodeMapRange *>(ranges));
   }
@@ -174,7 +173,7 @@ UnicodeMap::~UnicodeMap() {
 }
 
 UnicodeMap::UnicodeMap(UnicodeMap &&other) noexcept
-  : encodingName{other.encodingName}
+  : encodingName{std::move(other.encodingName)}
   , kind{other.kind}
   , unicodeOut{other.unicodeOut}
   , len{other.len}
@@ -192,7 +191,6 @@ UnicodeMap::UnicodeMap(UnicodeMap &&other) noexcept
     func = other.func;
     break;
   }
-  other.encodingName = nullptr;
   other.eMaps = nullptr;
 }
 
@@ -258,7 +256,7 @@ void UnicodeMap::decRefCnt() {
 }
 
 bool UnicodeMap::match(const GooString *encodingNameA) const {
-  return !encodingName->cmp(encodingNameA);
+  return encodingName == encodingNameA->toStr();
 }
 
 int UnicodeMap::mapUnicode(Unicode u, char *buf, int bufSize) const {
@@ -328,7 +326,7 @@ UnicodeMapCache::~UnicodeMapCache() {
   }
 }
 
-UnicodeMap *UnicodeMapCache::getUnicodeMap(GooString *encodingName) {
+UnicodeMap *UnicodeMapCache::getUnicodeMap(const GooString *encodingName) {
   UnicodeMap *map;
   int i, j;
 
diff --git a/poppler/UnicodeMap.h b/poppler/UnicodeMap.h
index 641519b4..bf412bf3 100644
--- a/poppler/UnicodeMap.h
+++ b/poppler/UnicodeMap.h
@@ -31,6 +31,7 @@
 #include "poppler-config.h"
 #include "CharTypes.h"
 #include <atomic>
+#include <string>
 
 class GooString;
 
@@ -58,7 +59,7 @@ public:
 
   // Create the UnicodeMap specified by <encodingName>.  Sets the
   // initial reference count to 1.  Returns NULL on failure.
-  static UnicodeMap *parse(GooString *encodingNameA);
+  static UnicodeMap *parse(const GooString *encodingNameA);
 
   // Create a resident UnicodeMap.
   UnicodeMap(const char *encodingNameA, bool unicodeOutA,
@@ -82,7 +83,7 @@ public:
   void incRefCnt();
   void decRefCnt();
 
-  const GooString *getEncodingName() const { return encodingName; }
+  std::string getEncodingName() const { return encodingName; }
 
   bool isUnicode() const { return unicodeOut; }
 
@@ -98,9 +99,9 @@ public:
 
 private:
 
-  UnicodeMap(GooString *encodingNameA);
+  UnicodeMap(const std::string &encodingNameA);
 
-  GooString *encodingName;
+  std::string encodingName;
   UnicodeMapKind kind;
   bool unicodeOut;
   union {
@@ -129,7 +130,7 @@ public:
   // Get the UnicodeMap for <encodingName>.  Increments its reference
   // count; there will be one reference for the cache plus one for the
   // caller of this function.  Returns NULL on failure.
-  UnicodeMap *getUnicodeMap(GooString *encodingName);
+  UnicodeMap *getUnicodeMap(const GooString *encodingName);
 
 private:
 


More information about the poppler mailing list