From 4dc8c50f81bd78711bcfb432629800b8683102b6 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 14 Sep 2018 18:00:54 +0000 Subject: 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 Commit-Queue: Tom Sepez --- core/fpdfapi/page/cpdf_streamcontentparser.cpp | 39 +++++++++----------------- core/fpdfapi/page/cpdf_streamcontentparser.h | 7 ++--- 2 files changed, 15 insertions(+), 31 deletions(-) (limited to 'core/fpdfapi') 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( - 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( - 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 m_pObject; FX_Number m_Number; - struct { - int m_Len; - char m_Buffer[32]; - } m_Name; + ByteString m_Name; + std::unique_ptr m_pObject; }; static const int kParamBufSize = 16; -- cgit v1.2.3