summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2017-06-08 10:08:08 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-06-08 19:20:05 +0000
commit0915087c64d64023f503d466b73835c09d0ed3a3 (patch)
tree5cf007c8806d4e0631b4c235198916ceb80dadd6 /core
parentdefe54dbf60459972ff1c295af332ccdbbe15a70 (diff)
downloadpdfium-0915087c64d64023f503d466b73835c09d0ed3a3.tar.xz
Replacing CFX_ByteTextBuf with stringstream in cpdf_streamparser.cpp.
Loaded PDF Reference 1-7.pdf 10 times to test performance, no apparent changes. All measurements between 62s and 65s in all cases. Bug: pdfium:731 Change-Id: I0a39bae45fc19a6bae0c634c5c8ef1d952ded26a Reviewed-on: https://pdfium-review.googlesource.com/6390 Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/page/cpdf_streamparser.cpp60
1 files changed, 29 insertions, 31 deletions
diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp
index e8116cf980..c3dc54a734 100644
--- a/core/fpdfapi/page/cpdf_streamparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamparser.cpp
@@ -8,7 +8,9 @@
#include <limits.h>
+#include <algorithm>
#include <memory>
+#include <sstream>
#include <utility>
#include "core/fpdfapi/cpdf_modulemgr.h"
@@ -220,7 +222,7 @@ std::unique_ptr<CPDF_Stream> CPDF_StreamParser::ReadInlineStream(
memcpy(pData.get(), m_pBuf + m_Pos, dwStreamSize);
m_Pos += dwStreamSize;
}
- pDict->SetNewFor<CPDF_Number>("Length", (int)dwStreamSize);
+ pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(dwStreamSize));
return pdfium::MakeUnique<CPDF_Stream>(std::move(pData), dwStreamSize,
std::move(pDict));
}
@@ -473,7 +475,7 @@ CFX_ByteString CPDF_StreamParser::ReadString() {
return CFX_ByteString();
uint8_t ch = m_pBuf[m_Pos++];
- CFX_ByteTextBuf buf;
+ std::ostringstream buf;
int parlevel = 0;
int status = 0;
int iEscCode = 0;
@@ -482,20 +484,19 @@ CFX_ByteString CPDF_StreamParser::ReadString() {
case 0:
if (ch == ')') {
if (parlevel == 0) {
- if (buf.GetLength() > kMaxStringLength) {
- return CFX_ByteString(buf.GetBuffer(), kMaxStringLength);
- }
- return buf.MakeString();
+ return CFX_ByteString(
+ buf.str().c_str(),
+ std::min(static_cast<int>(buf.tellp()), kMaxStringLength));
}
parlevel--;
- buf.AppendChar(')');
+ buf << ')';
} else if (ch == '(') {
parlevel++;
- buf.AppendChar('(');
+ buf << '(';
} else if (ch == '\\') {
status = 1;
} else {
- buf.AppendChar((char)ch);
+ buf << static_cast<char>(ch);
}
break;
case 1:
@@ -505,21 +506,21 @@ CFX_ByteString CPDF_StreamParser::ReadString() {
break;
}
if (ch == 'n') {
- buf.AppendChar('\n');
+ buf << '\n';
} else if (ch == 'r') {
- buf.AppendChar('\r');
+ buf << '\r';
} else if (ch == 't') {
- buf.AppendChar('\t');
+ buf << '\t';
} else if (ch == 'b') {
- buf.AppendChar('\b');
+ buf << '\b';
} else if (ch == 'f') {
- buf.AppendChar('\f');
+ buf << '\f';
} else if (ch == '\r') {
status = 4;
break;
} else if (ch == '\n') {
} else {
- buf.AppendChar(ch);
+ buf << static_cast<char>(ch);
}
status = 0;
break;
@@ -529,7 +530,7 @@ CFX_ByteString CPDF_StreamParser::ReadString() {
iEscCode * 8 + FXSYS_DecimalCharToInt(static_cast<char>(ch));
status = 3;
} else {
- buf.AppendChar(iEscCode);
+ buf << static_cast<char>(iEscCode);
status = 0;
continue;
}
@@ -538,19 +539,18 @@ CFX_ByteString CPDF_StreamParser::ReadString() {
if (ch >= '0' && ch <= '7') {
iEscCode =
iEscCode * 8 + FXSYS_DecimalCharToInt(static_cast<char>(ch));
- buf.AppendChar(iEscCode);
+ buf << static_cast<char>(iEscCode);
status = 0;
} else {
- buf.AppendChar(iEscCode);
+ buf << static_cast<char>(iEscCode);
status = 0;
continue;
}
break;
case 4:
status = 0;
- if (ch != '\n') {
+ if (ch != '\n')
continue;
- }
break;
}
if (!PositionIsInBounds())
@@ -561,17 +561,16 @@ CFX_ByteString CPDF_StreamParser::ReadString() {
if (PositionIsInBounds())
++m_Pos;
- if (buf.GetLength() > kMaxStringLength) {
- return CFX_ByteString(buf.GetBuffer(), kMaxStringLength);
- }
- return buf.MakeString();
+ return CFX_ByteString(
+ buf.str().c_str(),
+ std::min(static_cast<int>(buf.tellp()), kMaxStringLength));
}
CFX_ByteString CPDF_StreamParser::ReadHexString() {
if (!PositionIsInBounds())
return CFX_ByteString();
- CFX_ByteTextBuf buf;
+ std::ostringstream buf;
bool bFirst = true;
int code = 0;
while (PositionIsInBounds()) {
@@ -588,17 +587,16 @@ CFX_ByteString CPDF_StreamParser::ReadHexString() {
code = val * 16;
} else {
code += val;
- buf.AppendByte((uint8_t)code);
+ buf << static_cast<uint8_t>(code);
}
bFirst = !bFirst;
}
if (!bFirst)
- buf.AppendChar((char)code);
-
- if (buf.GetLength() > kMaxStringLength)
- return CFX_ByteString(buf.GetBuffer(), kMaxStringLength);
+ buf << static_cast<char>(code);
- return buf.MakeString();
+ return CFX_ByteString(
+ buf.str().c_str(),
+ std::min(static_cast<int>(buf.tellp()), kMaxStringLength));
}
bool CPDF_StreamParser::PositionIsInBounds() const {