Make ContentParam::m_Name be a ByteString.
Currently this is an inline fixed-length char[] buffer. We make a byte
string out of this in many places, and the current implementation still
memcpy's, so the additional costs should be minimal.
Next, we can avoid special-casing names that are longer than the
fixed size.
Change-Id: I980463cbb2325a9d6080bb51a6dfb0dbd1b704b1
Reviewed-on: https://pdfium-review.googlesource.com/42430
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index 20892cc..0760e15 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -318,21 +318,9 @@
void CPDF_StreamContentParser::AddNameParam(const ByteStringView& bsName) {
ContentParam& param = m_ParamBuf[GetNextParamPos()];
- if (bsName.GetLength() > 32) {
- param.m_Type = ContentParam::OBJECT;
- param.m_pObject = pdfium::MakeUnique<CPDF_Name>(
- m_pDocument->GetByteStringPool(), PDF_NameDecode(bsName));
- } else {
- param.m_Type = ContentParam::NAME;
- if (bsName.Contains('#')) {
- ByteString str = PDF_NameDecode(bsName);
- memcpy(param.m_Name.m_Buffer, str.c_str(), str.GetLength());
- param.m_Name.m_Len = str.GetLength();
- } else {
- memcpy(param.m_Name.m_Buffer, bsName.raw_str(), bsName.GetLength());
- param.m_Name.m_Len = bsName.GetLength();
- }
- }
+ param.m_Type = ContentParam::NAME;
+ param.m_Name =
+ bsName.Contains('#') ? PDF_NameDecode(bsName) : ByteString(bsName);
}
void CPDF_StreamContentParser::AddNumberParam(const ByteStringView& str) {
@@ -381,8 +369,7 @@
if (param.m_Type == ContentParam::NAME) {
param.m_Type = ContentParam::OBJECT;
param.m_pObject = pdfium::MakeUnique<CPDF_Name>(
- m_pDocument->GetByteStringPool(),
- ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len));
+ m_pDocument->GetByteStringPool(), param.m_Name);
return param.m_pObject.get();
}
if (param.m_Type == ContentParam::OBJECT)
@@ -393,20 +380,20 @@
}
ByteString CPDF_StreamContentParser::GetString(uint32_t index) const {
- if (index >= m_ParamCount) {
+ if (index >= m_ParamCount)
return ByteString();
- }
+
int real_index = m_ParamStartPos + m_ParamCount - index - 1;
- if (real_index >= kParamBufSize) {
+ if (real_index >= kParamBufSize)
real_index -= kParamBufSize;
- }
+
const ContentParam& param = m_ParamBuf[real_index];
- if (param.m_Type == ContentParam::NAME) {
- return ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len);
- }
- if (param.m_Type == 0 && param.m_pObject) {
+ if (param.m_Type == ContentParam::NAME)
+ return param.m_Name;
+
+ if (param.m_Type == 0 && param.m_pObject)
return param.m_pObject->GetString();
- }
+
return ByteString();
}
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.h b/core/fpdfapi/page/cpdf_streamcontentparser.h
index 6417043..d9239fd 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.h
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.h
@@ -71,12 +71,9 @@
~ContentParam();
Type m_Type;
- std::unique_ptr<CPDF_Object> m_pObject;
FX_Number m_Number;
- struct {
- int m_Len;
- char m_Buffer[32];
- } m_Name;
+ ByteString m_Name;
+ std::unique_ptr<CPDF_Object> m_pObject;
};
static const int kParamBufSize = 16;