diff options
Diffstat (limited to 'Build/source/libs/poppler/poppler-src/poppler/UnicodeMap.cc')
-rw-r--r-- | Build/source/libs/poppler/poppler-src/poppler/UnicodeMap.cc | 106 |
1 files changed, 77 insertions, 29 deletions
diff --git a/Build/source/libs/poppler/poppler-src/poppler/UnicodeMap.cc b/Build/source/libs/poppler/poppler-src/poppler/UnicodeMap.cc index dabdce2ad3c..a7c59edf796 100644 --- a/Build/source/libs/poppler/poppler-src/poppler/UnicodeMap.cc +++ b/Build/source/libs/poppler/poppler-src/poppler/UnicodeMap.cc @@ -17,6 +17,7 @@ // Copyright (C) 2017 Albert Astals Cid <aacid@kde.org> // Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com> // Copyright (C) 2017 Jean Ghali <jghali@libertysurf.fr> +// Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de> // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -139,9 +140,6 @@ UnicodeMap::UnicodeMap(GooString *encodingNameA) { eMaps = nullptr; eMapsLen = 0; refCnt = 1; -#ifdef MULTITHREADED - gInitMutex(&mutex); -#endif } UnicodeMap::UnicodeMap(const char *encodingNameA, GBool unicodeOutA, @@ -154,9 +152,6 @@ UnicodeMap::UnicodeMap(const char *encodingNameA, GBool unicodeOutA, eMaps = nullptr; eMapsLen = 0; refCnt = 1; -#ifdef MULTITHREADED - gInitMutex(&mutex); -#endif } UnicodeMap::UnicodeMap(const char *encodingNameA, GBool unicodeOutA, @@ -168,9 +163,6 @@ UnicodeMap::UnicodeMap(const char *encodingNameA, GBool unicodeOutA, eMaps = nullptr; eMapsLen = 0; refCnt = 1; -#ifdef MULTITHREADED - gInitMutex(&mutex); -#endif } UnicodeMap::~UnicodeMap() { @@ -181,32 +173,88 @@ UnicodeMap::~UnicodeMap() { if (eMaps) { gfree(eMaps); } -#ifdef MULTITHREADED - gDestroyMutex(&mutex); -#endif +} + +UnicodeMap::UnicodeMap(UnicodeMap &&other) noexcept + : encodingName{other.encodingName} + , kind{other.kind} + , unicodeOut{other.unicodeOut} + , len{other.len} + , eMaps{other.eMaps} + , eMapsLen{other.eMapsLen} + , refCnt{1} +{ + switch (kind) { + case unicodeMapUser: + case unicodeMapResident: + ranges = other.ranges; + other.ranges = nullptr; + break; + case unicodeMapFunc: + func = other.func; + break; + } + other.encodingName = nullptr; + other.eMaps = nullptr; +} + +UnicodeMap& UnicodeMap::operator=(UnicodeMap &&other) noexcept +{ + if (this != &other) + swap(other); + return *this; +} + +void UnicodeMap::swap(UnicodeMap &other) noexcept +{ + using std::swap; + swap(encodingName, other.encodingName); + swap(unicodeOut, other.unicodeOut); + switch (kind) { + case unicodeMapUser: + case unicodeMapResident: + switch (other.kind) { + case unicodeMapUser: + case unicodeMapResident: + swap(ranges, other.ranges); + break; + case unicodeMapFunc: + { + const auto tmp = ranges; + func = other.func; + other.ranges = tmp; + break; + } + } + break; + case unicodeMapFunc: + switch (other.kind) { + case unicodeMapUser: + case unicodeMapResident: + { + const auto tmp = func; + ranges = other.ranges; + other.func = tmp; + break; + } + case unicodeMapFunc: + swap(func, other.func); + break; + } + break; + } + swap(kind, other.kind); + swap(len, other.len); + swap(eMaps, other.eMaps); + swap(eMapsLen, other.eMapsLen); } void UnicodeMap::incRefCnt() { -#ifdef MULTITHREADED - gLockMutex(&mutex); -#endif - ++refCnt; -#ifdef MULTITHREADED - gUnlockMutex(&mutex); -#endif + refCnt.fetch_add(1); } void UnicodeMap::decRefCnt() { - GBool done; - -#ifdef MULTITHREADED - gLockMutex(&mutex); -#endif - done = --refCnt == 0; -#ifdef MULTITHREADED - gUnlockMutex(&mutex); -#endif - if (done) { + if (refCnt.fetch_sub(1) == 1) { delete this; } } |