diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2018-05-08 15:30:07 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-05-08 15:30:07 +0000 |
commit | 3645dbcf8f6b830ad5b371b9aaae6ee2be33eb98 (patch) | |
tree | 018b8ff4fa4e16dfefc41f72beae1323cb625ec8 | |
parent | dec08c8d3fbc4e89748f2d655b32727cfab373ed (diff) | |
download | pdfium-3645dbcf8f6b830ad5b371b9aaae6ee2be33eb98.tar.xz |
[fm2js] Create fewer CFX_WideTextBuf classes
This CL modifies the formcalc transpiler to create less CFX_WideTextBuf
classes as we convert to JavaScript. This can take some pathalogical
formcal from 20sec to convert to .5sec.
Bug: chromium:834575
Change-Id: I428883297bbc3a6a325a4ab0ad51834f2f02ab82
Reviewed-on: https://pdfium-review.googlesource.com/32154
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
-rw-r--r-- | core/fxcrt/cfx_binarybuf.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/cxfa_fmexpression.cpp | 21 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp | 75 |
3 files changed, 46 insertions, 52 deletions
diff --git a/core/fxcrt/cfx_binarybuf.cpp b/core/fxcrt/cfx_binarybuf.cpp index 1243593a77..5ef907cb80 100644 --- a/core/fxcrt/cfx_binarybuf.cpp +++ b/core/fxcrt/cfx_binarybuf.cpp @@ -12,7 +12,7 @@ CFX_BinaryBuf::CFX_BinaryBuf() : m_AllocStep(0), m_AllocSize(0), m_DataSize(0) {} -CFX_BinaryBuf::~CFX_BinaryBuf() {} +CFX_BinaryBuf::~CFX_BinaryBuf() = default; void CFX_BinaryBuf::Delete(size_t start_index, size_t count) { if (!m_pBuffer || count > m_DataSize || start_index > m_DataSize - count) diff --git a/xfa/fxfa/fm2js/cxfa_fmexpression.cpp b/xfa/fxfa/fm2js/cxfa_fmexpression.cpp index b2995cae4c..a3c65a2203 100644 --- a/xfa/fxfa/fm2js/cxfa_fmexpression.cpp +++ b/xfa/fxfa/fm2js/cxfa_fmexpression.cpp @@ -362,24 +362,23 @@ bool CXFA_FMForExpression::ToJavaScript(CFX_WideTextBuf& js, ReturnType type) { WideString tmpName = IdentifierToName(m_wsVariant); js << L"var " << tmpName << L" = null;\n"; - CFX_WideTextBuf assign_txt; - if (!m_pAssignment->ToJavaScript(assign_txt, ReturnType::kInfered)) + js << L"for (" << tmpName << L" = pfm_rt.get_val("; + if (!m_pAssignment->ToJavaScript(js, ReturnType::kInfered)) return false; + js << L"); "; - CFX_WideTextBuf accessor_txt; - if (!m_pAccessor->ToJavaScript(accessor_txt, ReturnType::kInfered)) + js << tmpName << (m_bDirection ? kLessEqual : kGreaterEqual); + js << L"pfm_rt.get_val("; + if (!m_pAccessor->ToJavaScript(js, ReturnType::kInfered)) return false; + js << L"); "; - js << L"for (" << tmpName << L" = pfm_rt.get_val(" << assign_txt << L"); "; - js << tmpName << (m_bDirection ? kLessEqual : kGreaterEqual); - js << L"pfm_rt.get_val(" << accessor_txt << L"); "; js << tmpName << (m_bDirection ? kPlusEqual : kMinusEqual); if (m_pStep) { - CFX_WideTextBuf step_txt; - if (!m_pStep->ToJavaScript(step_txt, ReturnType::kInfered)) + js << L"pfm_rt.get_val("; + if (!m_pStep->ToJavaScript(js, ReturnType::kInfered)) return false; - - js << L"pfm_rt.get_val(" << step_txt << L")"; + js << L")"; } else { js << L"1"; } diff --git a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp index 82aada6438..0cfb37e8d0 100644 --- a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp +++ b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp @@ -239,15 +239,13 @@ bool CXFA_FMBinExpression::ToJavaScript(CFX_WideTextBuf& js, ReturnType type) { if (CXFA_IsTooBig(js) || !depthManager.IsWithinMaxDepth()) return false; - CFX_WideTextBuf exp1_txt; - if (!m_pExp1->ToJavaScript(exp1_txt, ReturnType::kInfered)) + js << L"pfm_rt." << m_OpName << L"("; + if (!m_pExp1->ToJavaScript(js, ReturnType::kInfered)) return false; - - CFX_WideTextBuf exp2_txt; - if (!m_pExp2->ToJavaScript(exp2_txt, ReturnType::kInfered)) + js << L", "; + if (!m_pExp2->ToJavaScript(js, ReturnType::kInfered)) return false; - - js << L"pfm_rt." << m_OpName << L"(" << exp1_txt << L", " << exp2_txt << L")"; + js << L")"; return !CXFA_IsTooBig(js); } @@ -373,11 +371,10 @@ bool CXFA_FMUnaryExpression::ToJavaScript(CFX_WideTextBuf& js, if (CXFA_IsTooBig(js) || !depthManager.IsWithinMaxDepth()) return false; - CFX_WideTextBuf exp_txt; - if (!m_pExp->ToJavaScript(exp_txt, ReturnType::kInfered)) + js << L"pfm_rt." << m_OpName.c_str() << L"("; + if (!m_pExp->ToJavaScript(js, ReturnType::kInfered)) return false; - - js << L"pfm_rt." << m_OpName.c_str() << L"(" << exp_txt << L")"; + js << L")"; return !CXFA_IsTooBig(js); } @@ -451,28 +448,28 @@ bool CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& js, ReturnType type) { uint32_t methodPara = IsMethodWithObjParam(funcName.MakeString()); if (methodPara > 0) { for (size_t i = 0; i < m_Arguments.size(); ++i) { - CFX_WideTextBuf expr_txt; - if (!m_Arguments[i]->ToJavaScript(expr_txt, ReturnType::kInfered)) - return false; - // Currently none of our expressions use objects for a parameter over // the 6th. Make sure we don't overflow the shift when doing this // check. If we ever need more the 32 object params we can revisit. + js << L"pfm_rt.get_"; if (i < 32 && (methodPara & (0x01 << i)) > 0) - js << L"pfm_rt.get_jsobj(" << expr_txt << L")"; + js << L"jsobj"; else - js << L"pfm_rt.get_val(" << expr_txt << L")"; + js << L"val"; + js << L"("; + if (!m_Arguments[i]->ToJavaScript(js, ReturnType::kInfered)) + return false; + js << L")"; if (i + 1 < m_Arguments.size()) js << L", "; } } else { for (const auto& expr : m_Arguments) { - CFX_WideTextBuf expr_txt; - if (!expr->ToJavaScript(expr_txt, ReturnType::kInfered)) + js << L"pfm_rt.get_val("; + if (!expr->ToJavaScript(js, ReturnType::kInfered)) return false; - - js << L"pfm_rt.get_val(" << expr_txt << L")"; + js << L")"; if (expr != m_Arguments.back()) js << L", "; } @@ -505,11 +502,10 @@ bool CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& js, ReturnType type) { if (isExistsFunc) { js << L"\n(\nfunction ()\n{\ntry\n{\n"; if (!m_Arguments.empty()) { - CFX_WideTextBuf expr_txt; - if (!m_Arguments[0]->ToJavaScript(expr_txt, ReturnType::kInfered)) + js << L"return "; + if (!m_Arguments[0]->ToJavaScript(js, ReturnType::kInfered)) return false; - - js << L"return " << expr_txt << L";\n}\n"; + js << L";\n}\n"; } else { js << L"return 0;\n}\n"; } @@ -645,19 +641,19 @@ bool CXFA_FMDotDotAccessorExpression::ToJavaScript(CFX_WideTextBuf& js, if (CXFA_IsTooBig(js) || !depthManager.IsWithinMaxDepth()) return false; - CFX_WideTextBuf exp1_txt; - if (!m_pExp1->ToJavaScript(exp1_txt, ReturnType::kInfered)) + js << L"pfm_rt.dotdot_acc("; + if (!m_pExp1->ToJavaScript(js, ReturnType::kInfered)) return false; + js << L", " << L"\""; + if (m_pExp1->GetOperatorToken() == TOKidentifier) { + if (!m_pExp1->ToJavaScript(js, ReturnType::kInfered)) + return false; + } - CFX_WideTextBuf exp2_txt; - if (!m_pExp2->ToJavaScript(exp2_txt, ReturnType::kInfered)) + js << L"\", \"" << m_wsIdentifier << L"\", "; + if (!m_pExp2->ToJavaScript(js, ReturnType::kInfered)) return false; - - js << L"pfm_rt.dotdot_acc(" << exp1_txt << L", " << L"\""; - if (m_pExp1->GetOperatorToken() == TOKidentifier) - js << exp1_txt; - - js << L"\", \"" << m_wsIdentifier << L"\", " << exp2_txt << L")"; + js << L")"; return !CXFA_IsTooBig(js); } @@ -676,17 +672,16 @@ bool CXFA_FMMethodCallExpression::ToJavaScript(CFX_WideTextBuf& js, if (CXFA_IsTooBig(js) || !depthManager.IsWithinMaxDepth()) return false; - CFX_WideTextBuf exp1_txt; - if (!m_pExp1->ToJavaScript(exp1_txt, ReturnType::kInfered)) - return false; - CFX_WideTextBuf exp2_txt; if (!m_pExp2->ToJavaScript(exp2_txt, ReturnType::kInfered)) return false; js << L"(\nfunction ()\n{\n"; js << L"var method_return_value = null;\n"; - js << L"var accessor_object = " << exp1_txt << L";\n"; + js << L"var accessor_object = "; + if (!m_pExp1->ToJavaScript(js, ReturnType::kInfered)) + return false; + js << L";\n"; js << L"if (pfm_rt.is_ary(accessor_object))\n{\n"; js << L"for(var index = accessor_object.length - 1; index > 1; " L"index--)\n{\n"; |