Change CPDF_Dictionary getters to take ByteStringView
Make it possible to call CPDF_Dictionary getter APIs without creating a
ByteString from a string literal. This is a follow-up to
https://pdfium-review.googlesource.com/91611 and leverages the work in
that CL to compare ByteStringViews. Change a few callers to avoid
ByteString creation if the key is actually a string literal.
Change-Id: I19c8188172f83e698ca3f2faf4ecc8735789bab4
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/132030
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
index a8e9e60..f21d51d 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
@@ -513,7 +513,7 @@
ByteString CPDF_PageContentGenerator::RealizeResource(
const CPDF_Object* pResource,
- const ByteString& bsType) const {
+ ByteStringView type) const {
DCHECK(pResource);
if (!obj_holder_->GetResources()) {
obj_holder_->SetResources(document_->NewIndirect<CPDF_Dictionary>());
@@ -523,16 +523,16 @@
}
RetainPtr<CPDF_Dictionary> resource_dict =
- obj_holder_->GetMutableResources()->GetOrCreateDictFor(bsType);
+ obj_holder_->GetMutableResources()->GetOrCreateDictFor(type);
const auto& all_removed_resources_map =
obj_holder_->all_removed_resources_map();
- auto it = all_removed_resources_map.find(bsType);
+ auto it = all_removed_resources_map.find(type);
const CPDF_PageObjectHolder::RemovedResourceMap* removed_resource_map =
it != all_removed_resources_map.end() ? &it->second : nullptr;
ByteString name;
int idnum = 1;
while (true) {
- name = ByteString::Format("FX%c%d", bsType[0], idnum);
+ name = ByteString::Format("FX%c%d", type[0], idnum);
// Avoid name collisions with existing `resource_dict` entries.
if (resource_dict->KeyExist(name.AsStringView())) {
idnum++;
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.h b/core/fpdfapi/edit/cpdf_pagecontentgenerator.h
index 8d99401..b37d06b 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.h
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.h
@@ -48,7 +48,7 @@
void ProcessText(fxcrt::ostringstream* buf, CPDF_TextObject* pTextObj);
ByteString GetOrCreateDefaultGraphics() const;
ByteString RealizeResource(const CPDF_Object* pResource,
- const ByteString& bsType) const;
+ ByteStringView type) const;
const CPDF_ContentMarks* ProcessContentMarks(fxcrt::ostringstream* buf,
const CPDF_PageObject* pPageObj,
const CPDF_ContentMarks* pPrev);
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
index 9669f83..f276a24 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
@@ -38,8 +38,8 @@
RetainPtr<const CPDF_Dictionary> TestGetResource(
CPDF_PageContentGenerator* pGen,
- const ByteString& type,
- const ByteString& name) {
+ ByteStringView type,
+ ByteStringView name) {
RetainPtr<const CPDF_Dictionary> pResources =
pGen->obj_holder_->GetResources();
return pResources->GetDictFor(type)->GetDictFor(name);
@@ -225,10 +225,11 @@
EXPECT_EQ(kExpectedStringEnd,
path_string.Last(kExpectedStringEnd.GetLength()));
ASSERT_GT(path_string.GetLength(), kExpectedStringMinLength);
- RetainPtr<const CPDF_Dictionary> external_gs = TestGetResource(
- &generator, "ExtGState",
- path_string.Substr(kExpectedStringStart.GetLength(),
- path_string.GetLength() - kExpectedStringMinLength));
+ RetainPtr<const CPDF_Dictionary> external_gs =
+ TestGetResource(&generator, "ExtGState",
+ path_string.AsStringView().Substr(
+ kExpectedStringStart.GetLength(),
+ path_string.GetLength() - kExpectedStringMinLength));
ASSERT_TRUE(external_gs);
EXPECT_EQ(0.5f, external_gs->GetFloatFor("ca"));
EXPECT_EQ(0.8f, external_gs->GetFloatFor("CA"));
@@ -312,13 +313,15 @@
EXPECT_EQ(kCompareString3, last_string.Last(kCompareString3.GetLength()));
RetainPtr<const CPDF_Dictionary> external_gs = TestGetResource(
&generator, "ExtGState",
- mid_string.First(mid_string.GetLength() - kCompareString2.GetLength()));
+ mid_string.AsStringView().First(mid_string.GetLength() -
+ kCompareString2.GetLength()));
ASSERT_TRUE(external_gs);
EXPECT_EQ(0.5f, external_gs->GetFloatFor("ca"));
EXPECT_EQ(0.8f, external_gs->GetFloatFor("CA"));
RetainPtr<const CPDF_Dictionary> font_dict = TestGetResource(
&generator, "Font",
- last_string.First(last_string.GetLength() - kCompareString3.GetLength()));
+ last_string.AsStringView().First(last_string.GetLength() -
+ kCompareString3.GetLength()));
ASSERT_TRUE(font_dict);
EXPECT_EQ("Font", font_dict->GetNameFor("Type"));
EXPECT_EQ("Type1", font_dict->GetNameFor("Subtype"));
@@ -387,9 +390,10 @@
EXPECT_EQ(compare_string2, text_string.Last(compare_string2.GetLength()));
RetainPtr<const CPDF_Dictionary> font_dict = TestGetResource(
&generator, "Font",
- text_string.Substr(compare_string1.GetLength(),
- text_string.GetLength() - compare_string1.GetLength() -
- compare_string2.GetLength()));
+ text_string.AsStringView().Substr(compare_string1.GetLength(),
+ text_string.GetLength() -
+ compare_string1.GetLength() -
+ compare_string2.GetLength()));
ASSERT_TRUE(font_dict);
EXPECT_TRUE(font_dict->GetObjNum());
EXPECT_EQ("Font", font_dict->GetNameFor("Type"));
diff --git a/core/fpdfapi/edit/cpdf_pageorganizer.cpp b/core/fpdfapi/edit/cpdf_pageorganizer.cpp
index 9fd7aba..a1810cd 100644
--- a/core/fpdfapi/edit/cpdf_pageorganizer.cpp
+++ b/core/fpdfapi/edit/cpdf_pageorganizer.cpp
@@ -46,7 +46,7 @@
info->SetNewFor<CPDF_String>("Producer", "PDFium");
}
- if (root->GetByteStringFor("Type", ByteString()).IsEmpty()) {
+ if (root->GetByteStringFor("Type", ByteStringView()).IsEmpty()) {
root->SetNewFor<CPDF_Name>("Type", "Catalog");
}
@@ -59,7 +59,7 @@
pages = dest()->NewIndirect<CPDF_Dictionary>();
root->SetNewFor<CPDF_Reference>("Pages", dest(), pages->GetObjNum());
}
- if (pages->GetByteStringFor("Type", ByteString()).IsEmpty()) {
+ if (pages->GetByteStringFor("Type", ByteStringView()).IsEmpty()) {
pages->SetNewFor<CPDF_Name>("Type", "Pages");
}
@@ -165,8 +165,8 @@
bool CPDF_PageOrganizer::CopyInheritable(
RetainPtr<CPDF_Dictionary> dest_page_dict,
RetainPtr<const CPDF_Dictionary> src_page_dict,
- const ByteString& key) {
- if (dest_page_dict->KeyExist(key.AsStringView())) {
+ ByteStringView key) {
+ if (dest_page_dict->KeyExist(key)) {
return true;
}
@@ -176,14 +176,14 @@
return false;
}
- dest_page_dict->SetFor(key, inheritable->Clone());
+ dest_page_dict->SetFor(ByteString(key), inheritable->Clone());
return true;
}
// static
RetainPtr<const CPDF_Object> CPDF_PageOrganizer::PageDictGetInheritableTag(
RetainPtr<const CPDF_Dictionary> dict,
- const ByteString& src_tag) {
+ ByteStringView src_tag) {
if (!dict || src_tag.IsEmpty()) {
return nullptr;
}
@@ -204,12 +204,12 @@
return nullptr;
}
- if (dict->KeyExist(src_tag.AsStringView())) {
+ if (dict->KeyExist(src_tag)) {
return dict->GetObjectFor(src_tag);
}
while (pp) {
- if (pp->KeyExist(src_tag.AsStringView())) {
+ if (pp->KeyExist(src_tag)) {
return pp->GetObjectFor(src_tag);
}
if (!pp->KeyExist(pdfium::page_object::kParent)) {
diff --git a/core/fpdfapi/edit/cpdf_pageorganizer.h b/core/fpdfapi/edit/cpdf_pageorganizer.h
index c3fa370..e9623a4 100644
--- a/core/fpdfapi/edit/cpdf_pageorganizer.h
+++ b/core/fpdfapi/edit/cpdf_pageorganizer.h
@@ -44,11 +44,11 @@
static bool CopyInheritable(RetainPtr<CPDF_Dictionary> dest_page_dict,
RetainPtr<const CPDF_Dictionary> src_page_dict,
- const ByteString& key);
+ ByteStringView key);
static RetainPtr<const CPDF_Object> PageDictGetInheritableTag(
RetainPtr<const CPDF_Dictionary> dict,
- const ByteString& src_tag);
+ ByteStringView src_tag);
private:
bool InitDestDoc();
diff --git a/core/fpdfapi/page/cpdf_contentmarkitem.cpp b/core/fpdfapi/page/cpdf_contentmarkitem.cpp
index ed2bf6a..021e521 100644
--- a/core/fpdfapi/page/cpdf_contentmarkitem.cpp
+++ b/core/fpdfapi/page/cpdf_contentmarkitem.cpp
@@ -18,7 +18,7 @@
RetainPtr<const CPDF_Dictionary> CPDF_ContentMarkItem::GetParam() const {
switch (param_type_) {
case kPropertiesDict:
- return properties_holder_->GetDictFor(property_name_);
+ return properties_holder_->GetDictFor(property_name_.AsStringView());
case kDirectDict:
return direct_dict_;
case kNone:
diff --git a/core/fpdfapi/page/cpdf_docpagedata.cpp b/core/fpdfapi/page/cpdf_docpagedata.cpp
index a27fcc9..e465333 100644
--- a/core/fpdfapi/page/cpdf_docpagedata.cpp
+++ b/core/fpdfapi/page/cpdf_docpagedata.cpp
@@ -319,8 +319,9 @@
RetainPtr<const CPDF_Dictionary> pList =
pResources->GetDictFor("ColorSpace");
if (pList) {
- return GetColorSpaceInternal(pList->GetDirectObjectFor(name).Get(),
- nullptr, pVisited, pVisitedInternal);
+ return GetColorSpaceInternal(
+ pList->GetDirectObjectFor(name.AsStringView()).Get(), nullptr,
+ pVisited, pVisitedInternal);
}
}
if (!pCS || !pResources) {
diff --git a/core/fpdfapi/page/cpdf_occontext.cpp b/core/fpdfapi/page/cpdf_occontext.cpp
index 0659232..21d662f 100644
--- a/core/fpdfapi/page/cpdf_occontext.cpp
+++ b/core/fpdfapi/page/cpdf_occontext.cpp
@@ -70,23 +70,17 @@
return pConfig;
}
-ByteString GetUsageTypeString(CPDF_OCContext::UsageType eType) {
- ByteString csState;
+ByteStringView GetUsageTypeString(CPDF_OCContext::UsageType eType) {
switch (eType) {
case CPDF_OCContext::kDesign:
- csState = "Design";
- break;
+ return "Design";
case CPDF_OCContext::kPrint:
- csState = "Print";
- break;
+ return "Print";
case CPDF_OCContext::kExport:
- csState = "Export";
- break;
+ return "Export";
default:
- csState = "View";
- break;
+ return "View";
}
- return csState;
}
} // namespace
@@ -99,7 +93,7 @@
CPDF_OCContext::~CPDF_OCContext() = default;
bool CPDF_OCContext::LoadOCGStateFromConfig(
- const ByteString& csConfig,
+ ByteStringView config,
const CPDF_Dictionary* pOCGDict) const {
RetainPtr<const CPDF_Dictionary> pConfig = GetConfig(document_, pOCGDict);
if (!pConfig) {
@@ -122,14 +116,14 @@
return bState;
}
- ByteString csFind = csConfig + "State";
+ ByteString csFind({config, "State"});
for (size_t i = 0; i < pArray->size(); i++) {
RetainPtr<const CPDF_Dictionary> pUsage = pArray->GetDictAt(i);
if (!pUsage) {
continue;
}
- if (pUsage->GetByteStringFor("Event", "View") != csConfig) {
+ if (pUsage->GetByteStringFor("Event", "View") != config) {
continue;
}
@@ -142,12 +136,12 @@
continue;
}
- RetainPtr<const CPDF_Dictionary> pState = pUsage->GetDictFor(csConfig);
+ RetainPtr<const CPDF_Dictionary> pState = pUsage->GetDictFor(config);
if (!pState) {
continue;
}
- bState = pState->GetByteStringFor(csFind) != "OFF";
+ bState = pState->GetByteStringFor(csFind.AsStringView()) != "OFF";
}
return bState;
}
@@ -157,24 +151,24 @@
return true;
}
- ByteString csState = GetUsageTypeString(usage_type_);
+ ByteStringView state = GetUsageTypeString(usage_type_);
RetainPtr<const CPDF_Dictionary> pUsage = pOCGDict->GetDictFor("Usage");
if (pUsage) {
- RetainPtr<const CPDF_Dictionary> pState = pUsage->GetDictFor(csState);
+ RetainPtr<const CPDF_Dictionary> pState = pUsage->GetDictFor(state);
if (pState) {
- ByteString csFind = csState + "State";
+ ByteString csFind({state, "State"});
if (pState->KeyExist(csFind.AsStringView())) {
- return pState->GetByteStringFor(csFind) != "OFF";
+ return pState->GetByteStringFor(csFind.AsStringView()) != "OFF";
}
}
- if (csState != "View") {
+ if (state != "View") {
pState = pUsage->GetDictFor("View");
if (pState && pState->KeyExist("ViewState")) {
return pState->GetByteStringFor("ViewState") != "OFF";
}
}
}
- return LoadOCGStateFromConfig(csState, pOCGDict);
+ return LoadOCGStateFromConfig(state, pOCGDict);
}
bool CPDF_OCContext::GetOCGVisible(const CPDF_Dictionary* pOCGDict) const {
diff --git a/core/fpdfapi/page/cpdf_occontext.h b/core/fpdfapi/page/cpdf_occontext.h
index cf6fb66..7985d54 100644
--- a/core/fpdfapi/page/cpdf_occontext.h
+++ b/core/fpdfapi/page/cpdf_occontext.h
@@ -32,7 +32,7 @@
CPDF_OCContext(CPDF_Document* pDoc, UsageType eUsageType);
~CPDF_OCContext() override;
- bool LoadOCGStateFromConfig(const ByteString& csConfig,
+ bool LoadOCGStateFromConfig(ByteStringView config,
const CPDF_Dictionary* pOCGDict) const;
bool LoadOCGState(const CPDF_Dictionary* pOCGDict) const;
bool GetOCGVisible(const CPDF_Dictionary* pOCGDict) const;
diff --git a/core/fpdfapi/page/cpdf_page.cpp b/core/fpdfapi/page/cpdf_page.cpp
index 5e1dbe2..d2cd7a5 100644
--- a/core/fpdfapi/page/cpdf_page.cpp
+++ b/core/fpdfapi/page/cpdf_page.cpp
@@ -85,8 +85,10 @@
const ByteString& name) const {
std::set<RetainPtr<const CPDF_Dictionary>> visited;
RetainPtr<const CPDF_Dictionary> pPageDict = GetDict();
+ ByteStringView name_view = name.AsStringView();
while (pPageDict && !pdfium::Contains(visited, pPageDict)) {
- RetainPtr<const CPDF_Object> pObj = pPageDict->GetDirectObjectFor(name);
+ RetainPtr<const CPDF_Object> pObj =
+ pPageDict->GetDirectObjectFor(name_view);
if (pObj) {
return pObj;
}
diff --git a/core/fpdfapi/page/cpdf_pageobjectholder.h b/core/fpdfapi/page/cpdf_pageobjectholder.h
index 04df989..e6a4fe9 100644
--- a/core/fpdfapi/page/cpdf_pageobjectholder.h
+++ b/core/fpdfapi/page/cpdf_pageobjectholder.h
@@ -11,6 +11,7 @@
#include <stdint.h>
#include <deque>
+#include <functional>
#include <map>
#include <memory>
#include <optional>
@@ -62,7 +63,8 @@
// Key: The resource dictionary name.
// Value: The entries removed from that dictionary.
- using AllRemovedResourcesMap = std::map<ByteString, RemovedResourceMap>;
+ using AllRemovedResourcesMap =
+ std::map<ByteString, RemovedResourceMap, std::less<>>;
using iterator = std::deque<std::unique_ptr<CPDF_PageObject>>::iterator;
using const_iterator =
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index 3ad222b..5bd02e8 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -626,7 +626,7 @@
if (pProperty->IsName()) {
ByteString property_name = pProperty->GetString();
RetainPtr<CPDF_Dictionary> pHolder = FindResourceHolder("Properties");
- if (!pHolder || !pHolder->GetDictFor(property_name)) {
+ if (!pHolder || !pHolder->GetDictFor(property_name.AsStringView())) {
return;
}
new_marks->AddMarkWithPropertiesHolder(tag, std::move(pHolder),
@@ -1203,7 +1203,8 @@
return nullptr;
}
- RetainPtr<CPDF_Dictionary> pDict = resources_->GetMutableDictFor(type);
+ RetainPtr<CPDF_Dictionary> pDict =
+ resources_->GetMutableDictFor(type.AsStringView());
if (pDict) {
return pDict;
}
@@ -1212,14 +1213,15 @@
return nullptr;
}
- return page_resources_->GetMutableDictFor(type);
+ return page_resources_->GetMutableDictFor(type.AsStringView());
}
RetainPtr<CPDF_Object> CPDF_StreamContentParser::FindResourceObj(
const ByteString& type,
const ByteString& name) {
RetainPtr<CPDF_Dictionary> pHolder = FindResourceHolder(type);
- return pHolder ? pHolder->GetMutableDirectObjectFor(name) : nullptr;
+ return pHolder ? pHolder->GetMutableDirectObjectFor(name.AsStringView())
+ : nullptr;
}
RetainPtr<CPDF_Font> CPDF_StreamContentParser::FindFont(
diff --git a/core/fpdfapi/parser/cpdf_dictionary.cpp b/core/fpdfapi/parser/cpdf_dictionary.cpp
index 9d1e008..20744f7 100644
--- a/core/fpdfapi/parser/cpdf_dictionary.cpp
+++ b/core/fpdfapi/parser/cpdf_dictionary.cpp
@@ -70,51 +70,51 @@
}
const CPDF_Object* CPDF_Dictionary::GetObjectForInternal(
- const ByteString& key) const {
+ ByteStringView key) const {
auto it = map_.find(key);
return it != map_.end() ? it->second.Get() : nullptr;
}
RetainPtr<const CPDF_Object> CPDF_Dictionary::GetObjectFor(
- const ByteString& key) const {
+ ByteStringView key) const {
return pdfium::WrapRetain(GetObjectForInternal(key));
}
RetainPtr<CPDF_Object> CPDF_Dictionary::GetMutableObjectFor(
- const ByteString& key) {
+ ByteStringView key) {
return pdfium::WrapRetain(
const_cast<CPDF_Object*>(GetObjectForInternal(key)));
}
const CPDF_Object* CPDF_Dictionary::GetDirectObjectForInternal(
- const ByteString& key) const {
+ ByteStringView key) const {
const CPDF_Object* p = GetObjectForInternal(key);
return p ? p->GetDirectInternal() : nullptr;
}
RetainPtr<const CPDF_Object> CPDF_Dictionary::GetDirectObjectFor(
- const ByteString& key) const {
+ ByteStringView key) const {
return pdfium::WrapRetain(GetDirectObjectForInternal(key));
}
RetainPtr<CPDF_Object> CPDF_Dictionary::GetMutableDirectObjectFor(
- const ByteString& key) {
+ ByteStringView key) {
return pdfium::WrapRetain(
const_cast<CPDF_Object*>(GetDirectObjectForInternal(key)));
}
-ByteString CPDF_Dictionary::GetByteStringFor(const ByteString& key) const {
+ByteString CPDF_Dictionary::GetByteStringFor(ByteStringView key) const {
const CPDF_Object* p = GetObjectForInternal(key);
return p ? p->GetString() : ByteString();
}
-ByteString CPDF_Dictionary::GetByteStringFor(const ByteString& key,
- const ByteString& def) const {
+ByteString CPDF_Dictionary::GetByteStringFor(ByteStringView key,
+ ByteStringView def) const {
const CPDF_Object* p = GetObjectForInternal(key);
return p ? p->GetString() : ByteString(def);
}
-WideString CPDF_Dictionary::GetUnicodeTextFor(const ByteString& key) const {
+WideString CPDF_Dictionary::GetUnicodeTextFor(ByteStringView key) const {
const CPDF_Object* p = GetObjectForInternal(key);
if (const CPDF_Reference* pRef = ToReference(p)) {
p = pRef->GetDirectInternal();
@@ -122,33 +122,32 @@
return p ? p->GetUnicodeText() : WideString();
}
-ByteString CPDF_Dictionary::GetNameFor(const ByteString& key) const {
+ByteString CPDF_Dictionary::GetNameFor(ByteStringView key) const {
const CPDF_Name* p = ToName(GetObjectForInternal(key));
return p ? p->GetString() : ByteString();
}
-bool CPDF_Dictionary::GetBooleanFor(const ByteString& key,
- bool bDefault) const {
+bool CPDF_Dictionary::GetBooleanFor(ByteStringView key, bool bDefault) const {
const CPDF_Object* p = GetObjectForInternal(key);
return ToBoolean(p) ? p->GetInteger() != 0 : bDefault;
}
-int CPDF_Dictionary::GetIntegerFor(const ByteString& key) const {
+int CPDF_Dictionary::GetIntegerFor(ByteStringView key) const {
const CPDF_Object* p = GetObjectForInternal(key);
return p ? p->GetInteger() : 0;
}
-int CPDF_Dictionary::GetIntegerFor(const ByteString& key, int def) const {
+int CPDF_Dictionary::GetIntegerFor(ByteStringView key, int def) const {
const CPDF_Object* p = GetObjectForInternal(key);
return p ? p->GetInteger() : def;
}
-int CPDF_Dictionary::GetDirectIntegerFor(const ByteString& key) const {
+int CPDF_Dictionary::GetDirectIntegerFor(ByteStringView key) const {
const CPDF_Number* p = ToNumber(GetObjectForInternal(key));
return p ? p->GetInteger() : 0;
}
-float CPDF_Dictionary::GetFloatFor(const ByteString& key) const {
+float CPDF_Dictionary::GetFloatFor(ByteStringView key) const {
const CPDF_Object* p = GetObjectForInternal(key);
return p ? p->GetNumber() : 0;
}
@@ -158,92 +157,90 @@
}
const CPDF_Dictionary* CPDF_Dictionary::GetDictForInternal(
- const ByteString& key) const {
+ ByteStringView key) const {
const CPDF_Object* p = GetDirectObjectForInternal(key);
return p ? p->GetDictInternal() : nullptr;
}
RetainPtr<const CPDF_Dictionary> CPDF_Dictionary::GetDictFor(
- const ByteString& key) const {
+ ByteStringView key) const {
return pdfium::WrapRetain(GetDictForInternal(key));
}
RetainPtr<CPDF_Dictionary> CPDF_Dictionary::GetMutableDictFor(
- const ByteString& key) {
+ ByteStringView key) {
return pdfium::WrapRetain(
const_cast<CPDF_Dictionary*>(GetDictForInternal(key)));
}
RetainPtr<CPDF_Dictionary> CPDF_Dictionary::GetOrCreateDictFor(
- const ByteString& key) {
+ ByteStringView key) {
RetainPtr<CPDF_Dictionary> result = GetMutableDictFor(key);
if (result) {
return result;
}
- return SetNewFor<CPDF_Dictionary>(key);
+ return SetNewFor<CPDF_Dictionary>(ByteString(key));
}
const CPDF_Array* CPDF_Dictionary::GetArrayForInternal(
- const ByteString& key) const {
+ ByteStringView key) const {
return ToArray(GetDirectObjectForInternal(key));
}
RetainPtr<const CPDF_Array> CPDF_Dictionary::GetArrayFor(
- const ByteString& key) const {
+ ByteStringView key) const {
return pdfium::WrapRetain(GetArrayForInternal(key));
}
-RetainPtr<CPDF_Array> CPDF_Dictionary::GetMutableArrayFor(
- const ByteString& key) {
+RetainPtr<CPDF_Array> CPDF_Dictionary::GetMutableArrayFor(ByteStringView key) {
return pdfium::WrapRetain(const_cast<CPDF_Array*>(GetArrayForInternal(key)));
}
-RetainPtr<CPDF_Array> CPDF_Dictionary::GetOrCreateArrayFor(
- const ByteString& key) {
+RetainPtr<CPDF_Array> CPDF_Dictionary::GetOrCreateArrayFor(ByteStringView key) {
RetainPtr<CPDF_Array> result = GetMutableArrayFor(key);
if (result) {
return result;
}
- return SetNewFor<CPDF_Array>(key);
+ return SetNewFor<CPDF_Array>(ByteString(key));
}
const CPDF_Stream* CPDF_Dictionary::GetStreamForInternal(
- const ByteString& key) const {
+ ByteStringView key) const {
return ToStream(GetDirectObjectForInternal(key));
}
RetainPtr<const CPDF_Stream> CPDF_Dictionary::GetStreamFor(
- const ByteString& key) const {
+ ByteStringView key) const {
return pdfium::WrapRetain(GetStreamForInternal(key));
}
RetainPtr<CPDF_Stream> CPDF_Dictionary::GetMutableStreamFor(
- const ByteString& key) {
+ ByteStringView key) {
return pdfium::WrapRetain(
const_cast<CPDF_Stream*>(GetStreamForInternal(key)));
}
const CPDF_Number* CPDF_Dictionary::GetNumberForInternal(
- const ByteString& key) const {
+ ByteStringView key) const {
return ToNumber(GetObjectForInternal(key));
}
RetainPtr<const CPDF_Number> CPDF_Dictionary::GetNumberFor(
- const ByteString& key) const {
+ ByteStringView key) const {
return pdfium::WrapRetain(GetNumberForInternal(key));
}
const CPDF_String* CPDF_Dictionary::GetStringForInternal(
- const ByteString& key) const {
+ ByteStringView key) const {
return ToString(GetObjectForInternal(key));
}
RetainPtr<const CPDF_String> CPDF_Dictionary::GetStringFor(
- const ByteString& key) const {
+ ByteStringView key) const {
return pdfium::WrapRetain(GetStringForInternal(key));
}
-CFX_FloatRect CPDF_Dictionary::GetRectFor(const ByteString& key) const {
+CFX_FloatRect CPDF_Dictionary::GetRectFor(ByteStringView key) const {
const CPDF_Array* pArray = GetArrayForInternal(key);
if (pArray) {
return pArray->GetRect();
@@ -251,7 +248,7 @@
return CFX_FloatRect();
}
-CFX_Matrix CPDF_Dictionary::GetMatrixFor(const ByteString& key) const {
+CFX_Matrix CPDF_Dictionary::GetMatrixFor(ByteStringView key) const {
const CPDF_Array* pArray = GetArrayForInternal(key);
if (pArray) {
return pArray->GetMatrix();
diff --git a/core/fpdfapi/parser/cpdf_dictionary.h b/core/fpdfapi/parser/cpdf_dictionary.h
index 0e47729..cc143e0 100644
--- a/core/fpdfapi/parser/cpdf_dictionary.h
+++ b/core/fpdfapi/parser/cpdf_dictionary.h
@@ -43,41 +43,41 @@
bool IsLocked() const { return !!lock_count_; }
size_t size() const { return map_.size(); }
- RetainPtr<const CPDF_Object> GetObjectFor(const ByteString& key) const;
- RetainPtr<CPDF_Object> GetMutableObjectFor(const ByteString& key);
+ RetainPtr<const CPDF_Object> GetObjectFor(ByteStringView key) const;
+ RetainPtr<CPDF_Object> GetMutableObjectFor(ByteStringView key);
- RetainPtr<const CPDF_Object> GetDirectObjectFor(const ByteString& key) const;
- RetainPtr<CPDF_Object> GetMutableDirectObjectFor(const ByteString& key);
+ RetainPtr<const CPDF_Object> GetDirectObjectFor(ByteStringView key) const;
+ RetainPtr<CPDF_Object> GetMutableDirectObjectFor(ByteStringView key);
// These will return the string representation of the object specified by
// |key|, for any object type that has a string representation.
- ByteString GetByteStringFor(const ByteString& key) const;
- ByteString GetByteStringFor(const ByteString& key,
- const ByteString& default_str) const;
- WideString GetUnicodeTextFor(const ByteString& key) const;
+ ByteString GetByteStringFor(ByteStringView key) const;
+ ByteString GetByteStringFor(ByteStringView key,
+ ByteStringView default_str) const;
+ WideString GetUnicodeTextFor(ByteStringView key) const;
// This will only return the string representation of a name object specified
// by |key|. Useful when the PDF spec requires the value to be an object of
// type name. i.e. /Foo and not (Foo).
- ByteString GetNameFor(const ByteString& key) const;
+ ByteString GetNameFor(ByteStringView key) const;
- bool GetBooleanFor(const ByteString& key, bool bDefault) const;
- int GetIntegerFor(const ByteString& key) const;
- int GetIntegerFor(const ByteString& key, int default_int) const;
- int GetDirectIntegerFor(const ByteString& key) const;
- float GetFloatFor(const ByteString& key) const;
- RetainPtr<const CPDF_Dictionary> GetDictFor(const ByteString& key) const;
- RetainPtr<CPDF_Dictionary> GetMutableDictFor(const ByteString& key);
- RetainPtr<CPDF_Dictionary> GetOrCreateDictFor(const ByteString& key);
- RetainPtr<const CPDF_Array> GetArrayFor(const ByteString& key) const;
- RetainPtr<CPDF_Array> GetMutableArrayFor(const ByteString& key);
- RetainPtr<CPDF_Array> GetOrCreateArrayFor(const ByteString& key);
- RetainPtr<const CPDF_Stream> GetStreamFor(const ByteString& key) const;
- RetainPtr<CPDF_Stream> GetMutableStreamFor(const ByteString& key);
- RetainPtr<const CPDF_Number> GetNumberFor(const ByteString& key) const;
- RetainPtr<const CPDF_String> GetStringFor(const ByteString& key) const;
- CFX_FloatRect GetRectFor(const ByteString& key) const;
- CFX_Matrix GetMatrixFor(const ByteString& key) const;
+ bool GetBooleanFor(ByteStringView key, bool bDefault) const;
+ int GetIntegerFor(ByteStringView key) const;
+ int GetIntegerFor(ByteStringView key, int default_int) const;
+ int GetDirectIntegerFor(ByteStringView key) const;
+ float GetFloatFor(ByteStringView key) const;
+ RetainPtr<const CPDF_Dictionary> GetDictFor(ByteStringView key) const;
+ RetainPtr<CPDF_Dictionary> GetMutableDictFor(ByteStringView key);
+ RetainPtr<CPDF_Dictionary> GetOrCreateDictFor(ByteStringView key);
+ RetainPtr<const CPDF_Array> GetArrayFor(ByteStringView key) const;
+ RetainPtr<CPDF_Array> GetMutableArrayFor(ByteStringView key);
+ RetainPtr<CPDF_Array> GetOrCreateArrayFor(ByteStringView key);
+ RetainPtr<const CPDF_Stream> GetStreamFor(ByteStringView key) const;
+ RetainPtr<CPDF_Stream> GetMutableStreamFor(ByteStringView key);
+ RetainPtr<const CPDF_Number> GetNumberFor(ByteStringView key) const;
+ RetainPtr<const CPDF_String> GetStringFor(ByteStringView key) const;
+ CFX_FloatRect GetRectFor(ByteStringView key) const;
+ CFX_Matrix GetMatrixFor(ByteStringView key) const;
bool KeyExist(ByteStringView key) const;
std::vector<ByteString> GetKeys() const;
@@ -133,13 +133,13 @@
~CPDF_Dictionary() override;
// No guarantees about result lifetime, use with caution.
- const CPDF_Object* GetObjectForInternal(const ByteString& key) const;
- const CPDF_Object* GetDirectObjectForInternal(const ByteString& key) const;
- const CPDF_Array* GetArrayForInternal(const ByteString& key) const;
- const CPDF_Dictionary* GetDictForInternal(const ByteString& key) const;
- const CPDF_Number* GetNumberForInternal(const ByteString& key) const;
- const CPDF_Stream* GetStreamForInternal(const ByteString& key) const;
- const CPDF_String* GetStringForInternal(const ByteString& key) const;
+ const CPDF_Object* GetObjectForInternal(ByteStringView key) const;
+ const CPDF_Object* GetDirectObjectForInternal(ByteStringView key) const;
+ const CPDF_Array* GetArrayForInternal(ByteStringView key) const;
+ const CPDF_Dictionary* GetDictForInternal(ByteStringView key) const;
+ const CPDF_Number* GetNumberForInternal(ByteStringView key) const;
+ const CPDF_Stream* GetStreamForInternal(ByteStringView key) const;
+ const CPDF_String* GetStringForInternal(ByteStringView key) const;
CPDF_Object* SetForInternal(const ByteString& key,
RetainPtr<CPDF_Object> pObj);
diff --git a/core/fpdfapi/parser/cpdf_linearized_header.cpp b/core/fpdfapi/parser/cpdf_linearized_header.cpp
index d984e5f..81ad7d1 100644
--- a/core/fpdfapi/parser/cpdf_linearized_header.cpp
+++ b/core/fpdfapi/parser/cpdf_linearized_header.cpp
@@ -32,8 +32,7 @@
if (!pDict->KeyExist(key)) {
return !must_exist;
}
- // TODO(thestig): Avoid ByteString creation.
- RetainPtr<const CPDF_Number> pNum = pDict->GetNumberFor(ByteString(key));
+ RetainPtr<const CPDF_Number> pNum = pDict->GetNumberFor(key);
if (!pNum || !pNum->IsInteger()) {
return false;
}
diff --git a/core/fpdfapi/parser/cpdf_object_unittest.cpp b/core/fpdfapi/parser/cpdf_object_unittest.cpp
index 9e710ec..34e2972 100644
--- a/core/fpdfapi/parser/cpdf_object_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_object_unittest.cpp
@@ -154,7 +154,7 @@
CPDF_DictionaryLocker locker1(dict1);
for (const auto& item : locker1) {
if (!Equal(item.second.Get(),
- dict2->GetObjectFor(item.first).Get())) {
+ dict2->GetObjectFor(item.first.AsStringView()).Get())) {
return false;
}
}
diff --git a/core/fpdfapi/parser/cpdf_object_walker_unittest.cpp b/core/fpdfapi/parser/cpdf_object_walker_unittest.cpp
index 761da82..3fe6b10 100644
--- a/core/fpdfapi/parser/cpdf_object_walker_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_object_walker_unittest.cpp
@@ -151,7 +151,7 @@
}
// Test that, dictionary key is correct.
EXPECT_EQ(walker.GetParent()->AsDictionary()->GetObjectFor(
- walker.dictionary_key()),
+ walker.dictionary_key().AsStringView()),
obj);
}
}
diff --git a/core/fpdfapi/parser/cpdf_security_handler.cpp b/core/fpdfapi/parser/cpdf_security_handler.cpp
index efd63c6..2b7616d 100644
--- a/core/fpdfapi/parser/cpdf_security_handler.cpp
+++ b/core/fpdfapi/parser/cpdf_security_handler.cpp
@@ -247,7 +247,7 @@
*cipher = CPDF_CryptoHandler::Cipher::kNone;
} else {
RetainPtr<const CPDF_Dictionary> pDefFilter =
- pCryptFilters->GetDictFor(name);
+ pCryptFilters->GetDictFor(name.AsStringView());
if (!pDefFilter) {
return false;
}
diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp
index 73aed4a..5a0e186 100644
--- a/core/fpdfdoc/cpdf_annot.cpp
+++ b/core/fpdfdoc/cpdf_annot.cpp
@@ -120,7 +120,7 @@
as = (!value.IsEmpty() && pDict->KeyExist(value.AsStringView())) ? value
: "Off";
}
- return pDict->GetMutableStreamFor(as);
+ return pDict->GetMutableStreamFor(as.AsStringView());
}
} // namespace
diff --git a/core/fpdfdoc/cpdf_apsettings.cpp b/core/fpdfdoc/cpdf_apsettings.cpp
index 458a31f..f3bff09 100644
--- a/core/fpdfdoc/cpdf_apsettings.cpp
+++ b/core/fpdfdoc/cpdf_apsettings.cpp
@@ -35,7 +35,8 @@
return {CFX_Color::Type::kTransparent, 0};
}
- RetainPtr<const CPDF_Array> pEntry = dict_->GetArrayFor(csEntry);
+ RetainPtr<const CPDF_Array> pEntry =
+ dict_->GetArrayFor(csEntry.AsStringView());
if (!pEntry) {
return {CFX_Color::Type::kTransparent, 0};
}
@@ -71,7 +72,8 @@
return 0;
}
- RetainPtr<const CPDF_Array> pEntry = dict_->GetArrayFor(csEntry);
+ RetainPtr<const CPDF_Array> pEntry =
+ dict_->GetArrayFor(csEntry.AsStringView());
return pEntry ? pEntry->GetFloatAt(index) : 0;
}
@@ -80,7 +82,8 @@
return CFX_Color();
}
- RetainPtr<const CPDF_Array> pEntry = dict_->GetArrayFor(csEntry);
+ RetainPtr<const CPDF_Array> pEntry =
+ dict_->GetArrayFor(csEntry.AsStringView());
if (!pEntry) {
return CFX_Color();
}
@@ -102,12 +105,13 @@
}
WideString CPDF_ApSettings::GetCaption(const ByteString& csEntry) const {
- return dict_ ? dict_->GetUnicodeTextFor(csEntry) : WideString();
+ return dict_ ? dict_->GetUnicodeTextFor(csEntry.AsStringView())
+ : WideString();
}
RetainPtr<CPDF_Stream> CPDF_ApSettings::GetIcon(
const ByteString& csEntry) const {
- return dict_ ? dict_->GetMutableStreamFor(csEntry) : nullptr;
+ return dict_ ? dict_->GetMutableStreamFor(csEntry.AsStringView()) : nullptr;
}
CPDF_IconFit CPDF_ApSettings::GetIconFit() const {
diff --git a/core/fpdfdoc/cpdf_bafontmap.cpp b/core/fpdfdoc/cpdf_bafontmap.cpp
index be71841..217a198 100644
--- a/core/fpdfdoc/cpdf_bafontmap.cpp
+++ b/core/fpdfdoc/cpdf_bafontmap.cpp
@@ -292,7 +292,7 @@
pNormalDict->GetMutableDictFor("Resources")) {
if (RetainPtr<CPDF_Dictionary> pResFontDict =
pNormalResDict->GetMutableDictFor("Font")) {
- pFontDict = pResFontDict->GetMutableDictFor(*sAlias);
+ pFontDict = pResFontDict->GetMutableDictFor(sAlias->AsStringView());
}
}
}
@@ -302,7 +302,7 @@
pAcroFormDict->GetMutableDictFor("DR")) {
if (RetainPtr<CPDF_Dictionary> pDRFontDict =
pDRDict->GetMutableDictFor("Font")) {
- pFontDict = pDRFontDict->GetMutableDictFor(*sAlias);
+ pFontDict = pDRFontDict->GetMutableDictFor(sAlias->AsStringView());
}
}
}
@@ -323,11 +323,12 @@
annot_dict_->GetOrCreateDictFor(pdfium::annotation::kAP);
// to avoid checkbox and radiobutton
- if (ToDictionary(pAPDict->GetObjectFor(ap_type_))) {
+ if (ToDictionary(pAPDict->GetObjectFor(ap_type_.AsStringView()))) {
return;
}
- RetainPtr<CPDF_Stream> stream = pAPDict->GetMutableStreamFor(ap_type_);
+ RetainPtr<CPDF_Stream> stream =
+ pAPDict->GetMutableStreamFor(ap_type_.AsStringView());
if (!stream) {
stream =
document_->NewIndirect<CPDF_Stream>(document_->New<CPDF_Dictionary>());
diff --git a/core/fpdfdoc/cpdf_filespec.cpp b/core/fpdfdoc/cpdf_filespec.cpp
index e3eca22..5f33b8e 100644
--- a/core/fpdfdoc/cpdf_filespec.cpp
+++ b/core/fpdfdoc/cpdf_filespec.cpp
@@ -152,7 +152,7 @@
{"UF", "F", "DOS", "Mac", "Unix"}};
size_t end = pDict->GetByteStringFor("FS") == "URL" ? 2 : std::size(kKeys);
for (size_t i = 0; i < end; ++i) {
- ByteString key = kKeys[i];
+ ByteStringView key = kKeys[i];
if (!pDict->GetUnicodeTextFor(key).IsEmpty()) {
RetainPtr<const CPDF_Stream> pStream = pFiles->GetStreamFor(key);
if (pStream) {
diff --git a/core/fpdfdoc/cpdf_formcontrol.cpp b/core/fpdfdoc/cpdf_formcontrol.cpp
index 2f51e68..77e50d3 100644
--- a/core/fpdfdoc/cpdf_formcontrol.cpp
+++ b/core/fpdfdoc/cpdf_formcontrol.cpp
@@ -229,7 +229,7 @@
RetainPtr<CPDF_Dictionary> pFonts = pDRDict->GetMutableDictFor("Font");
if (ValidateFontResourceDict(pFonts.Get())) {
RetainPtr<CPDF_Dictionary> pElement =
- pFonts->GetMutableDictFor(font_name);
+ pFonts->GetMutableDictFor(font_name.AsStringView());
if (pElement) {
RetainPtr<CPDF_Font> pFont =
form_->GetFontForElement(std::move(pElement));
@@ -256,7 +256,8 @@
return nullptr;
}
- RetainPtr<CPDF_Dictionary> pElement = pFonts->GetMutableDictFor(font_name);
+ RetainPtr<CPDF_Dictionary> pElement =
+ pFonts->GetMutableDictFor(font_name.AsStringView());
if (!pElement) {
return nullptr;
}
diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp
index 887234d..93619ee 100644
--- a/core/fpdfdoc/cpdf_formfield.cpp
+++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -35,7 +35,7 @@
RetainPtr<const CPDF_Object> GetFieldAttrRecursive(
const CPDF_Dictionary* pFieldDict,
- const ByteString& name,
+ ByteStringView name,
int nLevel) {
static constexpr int kGetFieldMaxRecursion = 32;
if (!pFieldDict || nLevel > kGetFieldMaxRecursion) {
@@ -77,7 +77,7 @@
RetainPtr<const CPDF_Object> CPDF_FormField::GetFieldAttrForDict(
const CPDF_Dictionary* pFieldDict,
const ByteString& name) {
- return GetFieldAttrRecursive(pFieldDict, name, 0);
+ return GetFieldAttrRecursive(pFieldDict, name.AsStringView(), 0);
}
// static
@@ -85,7 +85,7 @@
CPDF_Dictionary* pFieldDict,
const ByteString& name) {
return pdfium::WrapRetain(const_cast<CPDF_Object*>(
- GetFieldAttrRecursive(pFieldDict, name, 0).Get()));
+ GetFieldAttrRecursive(pFieldDict, name.AsStringView(), 0).Get()));
}
// static
@@ -403,7 +403,7 @@
if (iIndex < 0) {
if (type_ == kRichText && !bDefault) {
dict_->SetFor(pdfium::form_fields::kRV,
- dict_->GetObjectFor(key)->Clone());
+ dict_->GetObjectFor(key.AsStringView())->Clone());
}
dict_->RemoveFor("I");
} else {
@@ -975,7 +975,7 @@
RetainPtr<const CPDF_Object> CPDF_FormField::GetFieldAttrInternal(
const ByteString& name) const {
- return GetFieldAttrRecursive(dict_.Get(), name, 0);
+ return GetFieldAttrRecursive(dict_.Get(), name.AsStringView(), 0);
}
const CPDF_Dictionary* CPDF_FormField::GetFieldDictInternal() const {
diff --git a/core/fpdfdoc/cpdf_generateap.cpp b/core/fpdfdoc/cpdf_generateap.cpp
index e921bd3..03077e2 100644
--- a/core/fpdfdoc/cpdf_generateap.cpp
+++ b/core/fpdfdoc/cpdf_generateap.cpp
@@ -620,7 +620,7 @@
CPDF_Dictionary* dr_font_dict,
const ByteString& font_name) {
RetainPtr<CPDF_Dictionary> font_dict =
- dr_font_dict->GetMutableDictFor(font_name);
+ dr_font_dict->GetMutableDictFor(font_name.AsStringView());
if (font_dict) {
return font_dict;
}
diff --git a/core/fpdfdoc/cpdf_interactiveform.cpp b/core/fpdfdoc/cpdf_interactiveform.cpp
index aec0dcc..1586adc 100644
--- a/core/fpdfdoc/cpdf_interactiveform.cpp
+++ b/core/fpdfdoc/cpdf_interactiveform.cpp
@@ -799,7 +799,8 @@
return nullptr;
}
- RetainPtr<CPDF_Dictionary> element = font_dict->GetMutableDictFor(alias);
+ RetainPtr<CPDF_Dictionary> element =
+ font_dict->GetMutableDictFor(alias.AsStringView());
if (!ValidateDictType(element.Get(), "Font")) {
return nullptr;
}
diff --git a/core/fpdfdoc/cpdf_nametree.cpp b/core/fpdfdoc/cpdf_nametree.cpp
index 47fae4b..2daad61 100644
--- a/core/fpdfdoc/cpdf_nametree.cpp
+++ b/core/fpdfdoc/cpdf_nametree.cpp
@@ -450,7 +450,8 @@
if (!pDests) {
return nullptr;
}
- return GetNamedDestFromObject(pDests->GetDirectObjectFor(name));
+ return GetNamedDestFromObject(
+ pDests->GetDirectObjectFor(name.AsStringView()));
}
} // namespace
@@ -476,7 +477,8 @@
return nullptr;
}
- RetainPtr<CPDF_Dictionary> pCategory = pNames->GetMutableDictFor(category);
+ RetainPtr<CPDF_Dictionary> pCategory =
+ pNames->GetMutableDictFor(category.AsStringView());
if (!pCategory) {
return nullptr;
}
@@ -502,7 +504,8 @@
}
// Create the |category| dictionary if missing.
- RetainPtr<CPDF_Dictionary> pCategory = pNames->GetMutableDictFor(category);
+ RetainPtr<CPDF_Dictionary> pCategory =
+ pNames->GetMutableDictFor(category.AsStringView());
if (!pCategory) {
pCategory = pDoc->NewIndirect<CPDF_Dictionary>();
pCategory->SetNewFor<CPDF_Array>("Names");
diff --git a/core/fpdfdoc/cpdf_pagelabel.cpp b/core/fpdfdoc/cpdf_pagelabel.cpp
index 38cb2b8..74adad1 100644
--- a/core/fpdfdoc/cpdf_pagelabel.cpp
+++ b/core/fpdfdoc/cpdf_pagelabel.cpp
@@ -131,7 +131,7 @@
label = label_dict->GetUnicodeTextFor("P");
}
- ByteString style = label_dict->GetByteStringFor("S", ByteString());
+ ByteString style = label_dict->GetByteStringFor("S", ByteStringView());
int label_number =
page_index - lower_bound.value().key + label_dict->GetIntegerFor("St", 1);
label += GetLabelNumPortion(label_number, style);
diff --git a/core/fpdfdoc/cpdf_structtree.cpp b/core/fpdfdoc/cpdf_structtree.cpp
index eddd907..3b0e410 100644
--- a/core/fpdfdoc/cpdf_structtree.cpp
+++ b/core/fpdfdoc/cpdf_structtree.cpp
@@ -47,7 +47,7 @@
ByteString CPDF_StructTree::GetRoleMapNameFor(const ByteString& type) const {
if (role_map_) {
- ByteString mapped = role_map_->GetNameFor(type);
+ ByteString mapped = role_map_->GetNameFor(type.AsStringView());
if (!mapped.IsEmpty()) {
return mapped;
}
diff --git a/core/fpdfdoc/cpdf_viewerpreferences.cpp b/core/fpdfdoc/cpdf_viewerpreferences.cpp
index f6255fa..1cb8a62 100644
--- a/core/fpdfdoc/cpdf_viewerpreferences.cpp
+++ b/core/fpdfdoc/cpdf_viewerpreferences.cpp
@@ -48,7 +48,8 @@
return std::nullopt;
}
- RetainPtr<const CPDF_Name> pName = ToName(pDict->GetObjectFor(bsKey));
+ RetainPtr<const CPDF_Name> pName =
+ ToName(pDict->GetObjectFor(bsKey.AsStringView()));
if (!pName) {
return std::nullopt;
}
diff --git a/fpdfsdk/cpdfsdk_appstream.cpp b/fpdfsdk/cpdfsdk_appstream.cpp
index a6b4516..cddd133 100644
--- a/fpdfsdk/cpdfsdk_appstream.cpp
+++ b/fpdfsdk/cpdfsdk_appstream.cpp
@@ -1826,7 +1826,8 @@
void CPDFSDK_AppStream::AddImage(const ByteString& sAPType,
const CPDF_Stream* pImage) {
- RetainPtr<CPDF_Stream> pStream = dict_->GetMutableStreamFor(sAPType);
+ RetainPtr<CPDF_Stream> pStream =
+ dict_->GetMutableStreamFor(sAPType.AsStringView());
RetainPtr<CPDF_Dictionary> pStreamDict = pStream->GetMutableDict();
const ByteString sImageAlias = pImage->GetDict()->GetByteStringFor("Name");
@@ -1848,13 +1849,14 @@
parent_dict = dict_;
key = sAPType;
} else {
- parent_dict = dict_->GetOrCreateDictFor(sAPType);
+ parent_dict = dict_->GetOrCreateDictFor(sAPType.AsStringView());
key = sAPState;
}
// If `stream` is created by CreateModifiedAPStream(), then it is safe to
// edit, as it is not shared.
- RetainPtr<CPDF_Stream> stream = parent_dict->GetMutableStreamFor(key);
+ RetainPtr<CPDF_Stream> stream =
+ parent_dict->GetMutableStreamFor(key.AsStringView());
CPDF_Document* doc = widget_->GetPageView()->GetPDFDocument();
if (!doc->IsModifiedAPStream(stream.Get())) {
auto new_stream_dict = doc->New<CPDF_Dictionary>();
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp
index c232fe6..adb2813 100644
--- a/fpdfsdk/cpdfsdk_widget.cpp
+++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -396,7 +396,7 @@
case FormFieldType::kCheckBox:
case FormFieldType::kRadioButton:
if (const CPDF_Dictionary* pSubDict = pSub->AsDictionary()) {
- return !!pSubDict->GetStreamFor(GetAppState());
+ return !!pSubDict->GetStreamFor(GetAppState().AsStringView());
}
return false;
default:
diff --git a/fpdfsdk/fpdf_annot.cpp b/fpdfsdk/fpdf_annot.cpp
index 3ee31a6..d259908 100644
--- a/fpdfsdk/fpdf_annot.cpp
+++ b/fpdfsdk/fpdf_annot.cpp
@@ -724,12 +724,12 @@
pAnnotDict->SetNewFor<CPDF_Number>("CA", A / 255.f);
// Set the color of the annotation.
- ByteString key = type == FPDFANNOT_COLORTYPE_InteriorColor ? "IC" : "C";
+ ByteStringView key = type == FPDFANNOT_COLORTYPE_InteriorColor ? "IC" : "C";
RetainPtr<CPDF_Array> pColor = pAnnotDict->GetMutableArrayFor(key);
if (pColor) {
pColor->Clear();
} else {
- pColor = pAnnotDict->SetNewFor<CPDF_Array>(key);
+ pColor = pAnnotDict->SetNewFor<CPDF_Array>(ByteString(key));
}
pColor->AppendNew<CPDF_Number>(R / 255.f);
diff --git a/fpdfsdk/fpdf_attachment.cpp b/fpdfsdk/fpdf_attachment.cpp
index 4c0ea55..d468056 100644
--- a/fpdfsdk/fpdf_attachment.cpp
+++ b/fpdfsdk/fpdf_attachment.cpp
@@ -201,14 +201,14 @@
// SAFETY: required from caller.
auto buffer_span = UNSAFE_BUFFERS(SpanFromFPDFApiArgs(buffer, buflen));
- ByteString key_str = key;
- RetainPtr<const CPDF_Object> object = params->GetObjectFor(key_str);
+ ByteStringView key_view(key);
+ RetainPtr<const CPDF_Object> object = params->GetObjectFor(key_view);
if (!object || (!object->IsString() && !object->IsName())) {
// Per API description, return an empty string in these cases.
return Utf16EncodeMaybeCopyAndReturnLength(WideString(), buffer_span);
}
- if (key_str == kChecksumKey) {
+ if (key_view == kChecksumKey) {
RetainPtr<const CPDF_String> string_object = ToString(object);
if (string_object && string_object->IsHex()) {
ByteString encoded =
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp
index 30f8a54..eee23cb 100644
--- a/fpdfsdk/fpdf_edit_embeddertest.cpp
+++ b/fpdfsdk/fpdf_edit_embeddertest.cpp
@@ -234,9 +234,8 @@
EXPECT_TRUE(font_desc->KeyExist(present));
EXPECT_FALSE(font_desc->KeyExist(absent));
- // TODO(thestig): Avoid ByteString creation.
- auto streamAcc = pdfium::MakeRetain<CPDF_StreamAcc>(
- font_desc->GetStreamFor(ByteString(present)));
+ auto streamAcc =
+ pdfium::MakeRetain<CPDF_StreamAcc>(font_desc->GetStreamFor(present));
streamAcc->LoadAllDataRaw();
// Check that the font stream is the one that was provided
diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp
index dea1505..4518aba 100644
--- a/fpdfsdk/fpdf_flatten.cpp
+++ b/fpdfsdk/fpdf_flatten.cpp
@@ -426,7 +426,8 @@
}
if (!sAnnotState.IsEmpty()) {
- original_ap_stream = original_ap_dict->GetMutableStreamFor(sAnnotState);
+ original_ap_stream =
+ original_ap_dict->GetMutableStreamFor(sAnnotState.AsStringView());
} else {
if (original_ap_dict->size() > 0) {
CPDF_DictionaryLocker locker(original_ap_dict);
diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp
index 41cc204..bcaa18b 100644
--- a/fpdfsdk/fpdf_transformpage.cpp
+++ b/fpdfsdk/fpdf_transformpage.cpp
@@ -43,7 +43,7 @@
}
bool GetBoundingBox(const CPDF_Page* page,
- const ByteString& key,
+ ByteStringView key,
float* left,
float* bottom,
float* right,
diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp
index 7c7eb13..852e2c8 100644
--- a/fxjs/cjs_document.cpp
+++ b/fxjs/cjs_document.cpp
@@ -774,7 +774,7 @@
}
CJS_Result CJS_Document::getPropertyInternal(CJS_Runtime* pRuntime,
- const ByteString& propName) {
+ ByteStringView property_name) {
if (!form_fill_env_) {
return CJS_Result::Failure(JSMessage::kBadObjectError);
}
@@ -786,7 +786,7 @@
}
return CJS_Result::Success(pRuntime->NewString(
- pDictionary->GetUnicodeTextFor(propName).AsStringView()));
+ pDictionary->GetUnicodeTextFor(property_name).AsStringView()));
}
CJS_Result CJS_Document::get_creation_date(CJS_Runtime* pRuntime) {
diff --git a/fxjs/cjs_document.h b/fxjs/cjs_document.h
index 5a95059..87585de 100644
--- a/fxjs/cjs_document.h
+++ b/fxjs/cjs_document.h
@@ -300,7 +300,7 @@
pdfium::span<v8::Local<v8::Value>> params);
CJS_Result getPropertyInternal(CJS_Runtime* pRuntime,
- const ByteString& propName);
+ ByteStringView property_name);
CPDF_InteractiveForm* GetCoreInteractiveForm();
CPDFSDK_InteractiveForm* GetSDKInteractiveForm();