Change various CMap code to take a ByteStringView. ByteStringView modifications are cheaper than ByteString modifications. Minimize headers in fpdf_cmaps.* along the way and do IWYU. Change-Id: I3b32faaf81309a5ac2c8e07bc2937c73a11d8b7b Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/65650 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/cmaps/CNS1/cmaps_cns1.cpp b/core/fpdfapi/cmaps/CNS1/cmaps_cns1.cpp index 80c31d6..810104e 100644 --- a/core/fpdfapi/cmaps/CNS1/cmaps_cns1.cpp +++ b/core/fpdfapi/cmaps/CNS1/cmaps_cns1.cpp
@@ -6,6 +6,8 @@ #include "core/fpdfapi/cmaps/CNS1/cmaps_cns1.h" +#include "core/fxcrt/fx_memory.h" + const FXCMAP_CMap g_FXCMAP_CNS1_cmaps[] = { {"B5pc-H", g_FXCMAP_B5pc_H_0, nullptr, 247, 0, FXCMAP_CMap::Range, 0}, {"B5pc-V", g_FXCMAP_B5pc_V_0, nullptr, 12, 0, FXCMAP_CMap::Range, -1},
diff --git a/core/fpdfapi/cmaps/GB1/cmaps_gb1.cpp b/core/fpdfapi/cmaps/GB1/cmaps_gb1.cpp index 0ba0db7..a598091 100644 --- a/core/fpdfapi/cmaps/GB1/cmaps_gb1.cpp +++ b/core/fpdfapi/cmaps/GB1/cmaps_gb1.cpp
@@ -6,6 +6,8 @@ #include "core/fpdfapi/cmaps/GB1/cmaps_gb1.h" +#include "core/fxcrt/fx_memory.h" + const FXCMAP_CMap g_FXCMAP_GB1_cmaps[] = { {"GB-EUC-H", g_FXCMAP_GB_EUC_H_0, nullptr, 90, 0, FXCMAP_CMap::Range, 0}, {"GB-EUC-V", g_FXCMAP_GB_EUC_V_0, nullptr, 20, 0, FXCMAP_CMap::Range, -1},
diff --git a/core/fpdfapi/cmaps/Japan1/cmaps_japan1.cpp b/core/fpdfapi/cmaps/Japan1/cmaps_japan1.cpp index 9b9cfc3..5a48c77 100644 --- a/core/fpdfapi/cmaps/Japan1/cmaps_japan1.cpp +++ b/core/fpdfapi/cmaps/Japan1/cmaps_japan1.cpp
@@ -6,6 +6,8 @@ #include "core/fpdfapi/cmaps/Japan1/cmaps_japan1.h" +#include "core/fxcrt/fx_memory.h" + const FXCMAP_CMap g_FXCMAP_Japan1_cmaps[] = { {"83pv-RKSJ-H", g_FXCMAP_83pv_RKSJ_H_1, nullptr, 222, 0, FXCMAP_CMap::Range, 0},
diff --git a/core/fpdfapi/cmaps/Korea1/cmaps_korea1.cpp b/core/fpdfapi/cmaps/Korea1/cmaps_korea1.cpp index a95ab3e..7362ff8 100644 --- a/core/fpdfapi/cmaps/Korea1/cmaps_korea1.cpp +++ b/core/fpdfapi/cmaps/Korea1/cmaps_korea1.cpp
@@ -6,6 +6,8 @@ #include "core/fpdfapi/cmaps/Korea1/cmaps_korea1.h" +#include "core/fxcrt/fx_memory.h" + const FXCMAP_CMap g_FXCMAP_Korea1_cmaps[] = { {"KSC-EUC-H", g_FXCMAP_KSC_EUC_H_0, nullptr, 467, 0, FXCMAP_CMap::Range, 0}, {"KSC-EUC-V", g_FXCMAP_KSC_EUC_V_0, nullptr, 16, 0, FXCMAP_CMap::Range, -1},
diff --git a/core/fpdfapi/cmaps/fpdf_cmaps.cpp b/core/fpdfapi/cmaps/fpdf_cmaps.cpp index 750c04d..5c89faf 100644 --- a/core/fpdfapi/cmaps/fpdf_cmaps.cpp +++ b/core/fpdfapi/cmaps/fpdf_cmaps.cpp
@@ -8,8 +8,6 @@ #include <algorithm> -#include "third_party/base/span.h" - namespace { struct SingleCmap { @@ -30,7 +28,7 @@ } // namespace const FXCMAP_CMap* FindEmbeddedCMap(pdfium::span<const FXCMAP_CMap> pCMaps, - const ByteString& bsName) { + ByteStringView bsName) { for (size_t i = 0; i < pCMaps.size(); i++) { if (bsName == pCMaps[i].m_Name) return &pCMaps[i];
diff --git a/core/fpdfapi/cmaps/fpdf_cmaps.h b/core/fpdfapi/cmaps/fpdf_cmaps.h index c84dc57..2c7548a 100644 --- a/core/fpdfapi/cmaps/fpdf_cmaps.h +++ b/core/fpdfapi/cmaps/fpdf_cmaps.h
@@ -7,8 +7,9 @@ #ifndef CORE_FPDFAPI_CMAPS_FPDF_CMAPS_H_ #define CORE_FPDFAPI_CMAPS_FPDF_CMAPS_H_ +#include <stdint.h> + #include "core/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" #include "third_party/base/span.h" struct FXCMAP_DWordCIDMap { @@ -31,7 +32,7 @@ }; const FXCMAP_CMap* FindEmbeddedCMap(pdfium::span<const FXCMAP_CMap> pCMaps, - const ByteString& name); + ByteStringView name); uint16_t CIDFromCharCode(const FXCMAP_CMap* pMap, uint32_t charcode); uint32_t CharCodeFromCID(const FXCMAP_CMap* pMap, uint16_t cid);
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp index 19dbf86..0c02b9e 100644 --- a/core/fpdfapi/font/cpdf_cidfont.cpp +++ b/core/fpdfapi/font/cpdf_cidfont.cpp
@@ -360,7 +360,8 @@ } else if (CPDF_Stream* pStream = pEncoding->AsStream()) { auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pStream); pAcc->LoadAllDataFiltered(); - m_pCMap = pdfium::MakeRetain<CPDF_CMap>(pAcc->GetSpan()); + pdfium::span<const uint8_t> span = pAcc->GetSpan(); + m_pCMap = pdfium::MakeRetain<CPDF_CMap>(span); } else { return false; }
diff --git a/core/fpdfapi/font/cpdf_cmap.cpp b/core/fpdfapi/font/cpdf_cmap.cpp index 9d1603b..844bc5f 100644 --- a/core/fpdfapi/font/cpdf_cmap.cpp +++ b/core/fpdfapi/font/cpdf_cmap.cpp
@@ -181,12 +181,11 @@ {"UniKS-UTF16", CIDSET_KOREA1, CIDCODING_UTF16, CPDF_CMap::TwoBytes, 0, {}}, }; -const PredefinedCMap* GetPredefinedCMap(const ByteString& bsPredefinedName) { - ByteString cmapid = bsPredefinedName; +const PredefinedCMap* GetPredefinedCMap(ByteStringView cmapid) { if (cmapid.GetLength() > 2) cmapid = cmapid.First(cmapid.GetLength() - 2); for (const auto& map : kPredefinedCMaps) { - if (cmapid == ByteStringView(map.m_pName)) + if (cmapid == map.m_pName) return ↦ } return nullptr; @@ -258,7 +257,7 @@ } // namespace -CPDF_CMap::CPDF_CMap(const ByteString& bsPredefinedName) +CPDF_CMap::CPDF_CMap(ByteStringView bsPredefinedName) : m_bVertical(bsPredefinedName.Back() == 'V') { if (bsPredefinedName == "Identity-H" || bsPredefinedName == "Identity-V") { m_Coding = CIDCODING_CID;
diff --git a/core/fpdfapi/font/cpdf_cmap.h b/core/fpdfapi/font/cpdf_cmap.h index 6754c71..e2caf8d 100644 --- a/core/fpdfapi/font/cpdf_cmap.h +++ b/core/fpdfapi/font/cpdf_cmap.h
@@ -78,7 +78,7 @@ } private: - explicit CPDF_CMap(const ByteString& bsPredefinedName); + explicit CPDF_CMap(ByteStringView bsPredefinedName); explicit CPDF_CMap(pdfium::span<const uint8_t> spEmbeddedData); ~CPDF_CMap() override;
diff --git a/core/fpdfapi/font/cpdf_cmapmanager.cpp b/core/fpdfapi/font/cpdf_cmapmanager.cpp index 4129716..726b648 100644 --- a/core/fpdfapi/font/cpdf_cmapmanager.cpp +++ b/core/fpdfapi/font/cpdf_cmapmanager.cpp
@@ -14,7 +14,7 @@ namespace { -RetainPtr<const CPDF_CMap> LoadPredefinedCMap(ByteString name) { +RetainPtr<const CPDF_CMap> LoadPredefinedCMap(ByteStringView name) { if (!name.IsEmpty() && name[0] == '/') name = name.Last(name.GetLength() - 1); return pdfium::MakeRetain<CPDF_CMap>(name); @@ -32,7 +32,7 @@ if (it != m_CMaps.end()) return it->second; - RetainPtr<const CPDF_CMap> pCMap = LoadPredefinedCMap(name); + RetainPtr<const CPDF_CMap> pCMap = LoadPredefinedCMap(name.AsStringView()); if (!name.IsEmpty()) m_CMaps[name] = pCMap;