Vastly simplify CPDF_Type3Cache::m_SizeMap
Use a compound key of four ints rather than cobbling together a
string in an ad-hoc manner. Avoids pointer arithmetic as a
consequence.
Change-Id: I354bcbdaf2a4fd47ecf4eb81dd969616c0e99696
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/96954
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_type3cache.cpp b/core/fpdfapi/render/cpdf_type3cache.cpp
index 78c149b..dbb3e87 100644
--- a/core/fpdfapi/render/cpdf_type3cache.cpp
+++ b/core/fpdfapi/render/cpdf_type3cache.cpp
@@ -7,7 +7,6 @@
#include "core/fpdfapi/render/cpdf_type3cache.h"
#include <math.h>
-#include <stdarg.h>
#include <memory>
#include <utility>
@@ -23,24 +22,6 @@
namespace {
-struct UniqueKeyGen {
- void Generate(int count, ...);
-
- int m_KeyLen;
- char m_Key[128];
-};
-
-void UniqueKeyGen::Generate(int count, ...) {
- va_list argList;
- va_start(argList, count);
- for (int i = 0; i < count; i++) {
- int p = va_arg(argList, int);
- (reinterpret_cast<uint32_t*>(m_Key))[i] = p;
- }
- va_end(argList);
- m_KeyLen = count * sizeof(uint32_t);
-}
-
bool IsScanLine1bpp(const uint8_t* pBuf, int width) {
int size = width / 8;
for (int i = 0; i < size; i++) {
@@ -98,17 +79,18 @@
const CFX_GlyphBitmap* CPDF_Type3Cache::LoadGlyph(uint32_t charcode,
const CFX_Matrix& mtMatrix) {
- UniqueKeyGen keygen;
- keygen.Generate(
- 4, FXSYS_roundf(mtMatrix.a * 10000), FXSYS_roundf(mtMatrix.b * 10000),
- FXSYS_roundf(mtMatrix.c * 10000), FXSYS_roundf(mtMatrix.d * 10000));
- ByteString FaceGlyphsKey(keygen.m_Key, keygen.m_KeyLen);
+ SizeKey keygen = {
+ FXSYS_roundf(mtMatrix.a * 10000),
+ FXSYS_roundf(mtMatrix.b * 10000),
+ FXSYS_roundf(mtMatrix.c * 10000),
+ FXSYS_roundf(mtMatrix.d * 10000),
+ };
CPDF_Type3GlyphMap* pSizeCache;
- auto it = m_SizeMap.find(FaceGlyphsKey);
+ auto it = m_SizeMap.find(keygen);
if (it == m_SizeMap.end()) {
auto pNew = std::make_unique<CPDF_Type3GlyphMap>();
pSizeCache = pNew.get();
- m_SizeMap[FaceGlyphsKey] = std::move(pNew);
+ m_SizeMap[keygen] = std::move(pNew);
} else {
pSizeCache = it->second.get();
}
diff --git a/core/fpdfapi/render/cpdf_type3cache.h b/core/fpdfapi/render/cpdf_type3cache.h
index 7121327..d85387b 100644
--- a/core/fpdfapi/render/cpdf_type3cache.h
+++ b/core/fpdfapi/render/cpdf_type3cache.h
@@ -11,6 +11,7 @@
#include <map>
#include <memory>
+#include <tuple>
#include "core/fxcrt/bytestring.h"
#include "core/fxcrt/observed_ptr.h"
@@ -29,6 +30,8 @@
const CFX_Matrix& mtMatrix);
private:
+ using SizeKey = std::tuple<int, int, int, int>;
+
explicit CPDF_Type3Cache(CPDF_Type3Font* pFont);
~CPDF_Type3Cache() override;
@@ -37,7 +40,7 @@
const CFX_Matrix& mtMatrix);
RetainPtr<CPDF_Type3Font> const m_pFont;
- std::map<ByteString, std::unique_ptr<CPDF_Type3GlyphMap>> m_SizeMap;
+ std::map<SizeKey, std::unique_ptr<CPDF_Type3GlyphMap>> m_SizeMap;
};
#endif // CORE_FPDFAPI_RENDER_CPDF_TYPE3CACHE_H_