summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/javascript/Field.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2016-02-01 13:42:30 -0800
committerTom Sepez <tsepez@chromium.org>2016-02-01 13:42:30 -0800
commitb9cc7a0d0ece261db2cd2a1486b05e3338bca322 (patch)
treec91de6c7848ce9cdf6eaab0a84fac27064a00c48 /fpdfsdk/src/javascript/Field.cpp
parent58fb36a3de3174db41669c2ed0d67e4a18a4a6de (diff)
downloadpdfium-b9cc7a0d0ece261db2cd2a1486b05e3338bca322.tar.xz
Merge to XFA: Remove CGW_ArrayTemplate and its O(n^2 log n) sort.
Original Review URL: https://codereview.chromium.org/1652613002 . (cherry picked from commit 0841b0f37678ba4962247f5636e9390718fc027e) TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/1657663003 .
Diffstat (limited to 'fpdfsdk/src/javascript/Field.cpp')
-rw-r--r--fpdfsdk/src/javascript/Field.cpp35
1 files changed, 19 insertions, 16 deletions
diff --git a/fpdfsdk/src/javascript/Field.cpp b/fpdfsdk/src/javascript/Field.cpp
index 1b55515069..24acd6029c 100644
--- a/fpdfsdk/src/javascript/Field.cpp
+++ b/fpdfsdk/src/javascript/Field.cpp
@@ -6,6 +6,10 @@
#include "Field.h"
+#include <algorithm>
+#include <memory>
+#include <vector>
+
#include "Document.h"
#include "Icon.h"
#include "JS_Context.h"
@@ -3082,10 +3086,6 @@ FX_BOOL Field::deleteItemAt(IJS_Context* cc,
return TRUE;
}
-int JS_COMPARESTRING(CFX_WideString* ps1, CFX_WideString* ps2) {
- return ps1->Compare(*ps2);
-}
-
FX_BOOL Field::getArray(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
@@ -3094,35 +3094,38 @@ FX_BOOL Field::getArray(IJS_Context* cc,
if (FieldArray.empty())
return FALSE;
- CGW_ArrayTemplate<CFX_WideString*> swSort;
+ std::vector<std::unique_ptr<CFX_WideString>> swSort;
+ for (CPDF_FormField* pFormField : FieldArray) {
+ swSort.push_back(std::unique_ptr<CFX_WideString>(
+ new CFX_WideString(pFormField->GetFullName())));
+ }
- for (CPDF_FormField* pFormField : FieldArray)
- swSort.Add(new CFX_WideString(pFormField->GetFullName()));
- swSort.Sort(JS_COMPARESTRING);
+ std::sort(
+ swSort.begin(), swSort.end(),
+ [](const std::unique_ptr<CFX_WideString>& p1,
+ const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; });
CJS_Context* pContext = (CJS_Context*)cc;
CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime);
-
CJS_Array FormFieldArray(pRuntime);
- for (int j = 0, jsz = swSort.GetSize(); j < jsz; j++) {
- std::unique_ptr<CFX_WideString> pStr(swSort.GetAt(j));
+
+ int j = 0;
+ for (const auto& pStr : swSort) {
v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID);
ASSERT(!pObj.IsEmpty());
CJS_Field* pJSField =
- (CJS_Field*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
- Field* pField = (Field*)pJSField->GetEmbedObject();
+ static_cast<CJS_Field*>(FXJS_GetPrivate(pRuntime->GetIsolate(), pObj));
+ Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
pField->AttachField(m_pJSDoc, *pStr);
CJS_Value FormFieldValue(pRuntime);
FormFieldValue = pJSField;
- FormFieldArray.SetElement(j, FormFieldValue);
+ FormFieldArray.SetElement(j++, FormFieldValue);
}
vRet = FormFieldArray;
- swSort.RemoveAll();
return TRUE;
}