summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-09-14 18:00:54 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-09-14 18:00:54 +0000
commit4dc8c50f81bd78711bcfb432629800b8683102b6 (patch)
tree0c4f4b7d2311be5d8f93294199f2b6232df8c363
parent6719c2f8c2e7bb3e28c86f638fb7914af6789285 (diff)
downloadpdfium-4dc8c50f81bd78711bcfb432629800b8683102b6.tar.xz
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>
-rw-r--r--core/fpdfapi/page/cpdf_streamcontentparser.cpp39
-rw-r--r--core/fpdfapi/page/cpdf_streamcontentparser.h7
2 files changed, 15 insertions, 31 deletions
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index 20892cc264..0760e150f3 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -318,21 +318,9 @@ int CPDF_StreamContentParser::GetNextParamPos() {
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 @@ CPDF_Object* CPDF_StreamContentParser::GetObject(uint32_t index) {
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 @@ CPDF_Object* CPDF_StreamContentParser::GetObject(uint32_t index) {
}
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 6417043305..d9239fd6fa 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.h
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.h
@@ -71,12 +71,9 @@ class CPDF_StreamContentParser {
~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;