Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Unified Diff: fpdfsdk/src/javascript/Field.cpp

Issue 1657663003: Merge to XFA: Remove CGW_ArrayTemplate and its O(n^2 log n) sort. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fpdfsdk/src/fsdk_baseform.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/src/javascript/Field.cpp
diff --git a/fpdfsdk/src/javascript/Field.cpp b/fpdfsdk/src/javascript/Field.cpp
index 1b5551506988ff01d839af51883cc80fa21d1a4c..24acd6029ca096c9b5c183d1c585a16feef22db5 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;
}
« no previous file with comments | « fpdfsdk/src/fsdk_baseform.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698