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

Side by Side 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, 10 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 unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/fsdk_baseform.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "Field.h" 7 #include "Field.h"
8 8
9 #include <algorithm>
10 #include <memory>
11 #include <vector>
12
9 #include "Document.h" 13 #include "Document.h"
10 #include "Icon.h" 14 #include "Icon.h"
11 #include "JS_Context.h" 15 #include "JS_Context.h"
12 #include "JS_Define.h" 16 #include "JS_Define.h"
13 #include "JS_EventHandler.h" 17 #include "JS_EventHandler.h"
14 #include "JS_Object.h" 18 #include "JS_Object.h"
15 #include "JS_Runtime.h" 19 #include "JS_Runtime.h"
16 #include "JS_Value.h" 20 #include "JS_Value.h"
17 #include "PublicMethods.h" 21 #include "PublicMethods.h"
18 #include "color.h" 22 #include "color.h"
(...skipping 3056 matching lines...) Expand 10 before | Expand all | Expand 10 after
3075 return TRUE; 3079 return TRUE;
3076 } 3080 }
3077 3081
3078 FX_BOOL Field::deleteItemAt(IJS_Context* cc, 3082 FX_BOOL Field::deleteItemAt(IJS_Context* cc,
3079 const std::vector<CJS_Value>& params, 3083 const std::vector<CJS_Value>& params,
3080 CJS_Value& vRet, 3084 CJS_Value& vRet,
3081 CFX_WideString& sError) { 3085 CFX_WideString& sError) {
3082 return TRUE; 3086 return TRUE;
3083 } 3087 }
3084 3088
3085 int JS_COMPARESTRING(CFX_WideString* ps1, CFX_WideString* ps2) {
3086 return ps1->Compare(*ps2);
3087 }
3088
3089 FX_BOOL Field::getArray(IJS_Context* cc, 3089 FX_BOOL Field::getArray(IJS_Context* cc,
3090 const std::vector<CJS_Value>& params, 3090 const std::vector<CJS_Value>& params,
3091 CJS_Value& vRet, 3091 CJS_Value& vRet,
3092 CFX_WideString& sError) { 3092 CFX_WideString& sError) {
3093 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); 3093 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3094 if (FieldArray.empty()) 3094 if (FieldArray.empty())
3095 return FALSE; 3095 return FALSE;
3096 3096
3097 CGW_ArrayTemplate<CFX_WideString*> swSort; 3097 std::vector<std::unique_ptr<CFX_WideString>> swSort;
3098 for (CPDF_FormField* pFormField : FieldArray) {
3099 swSort.push_back(std::unique_ptr<CFX_WideString>(
3100 new CFX_WideString(pFormField->GetFullName())));
3101 }
3098 3102
3099 for (CPDF_FormField* pFormField : FieldArray) 3103 std::sort(
3100 swSort.Add(new CFX_WideString(pFormField->GetFullName())); 3104 swSort.begin(), swSort.end(),
3101 swSort.Sort(JS_COMPARESTRING); 3105 [](const std::unique_ptr<CFX_WideString>& p1,
3106 const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; });
3102 3107
3103 CJS_Context* pContext = (CJS_Context*)cc; 3108 CJS_Context* pContext = (CJS_Context*)cc;
3104 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 3109 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
3105 ASSERT(pRuntime); 3110 CJS_Array FormFieldArray(pRuntime);
3106 3111
3107 CJS_Array FormFieldArray(pRuntime); 3112 int j = 0;
3108 for (int j = 0, jsz = swSort.GetSize(); j < jsz; j++) { 3113 for (const auto& pStr : swSort) {
3109 std::unique_ptr<CFX_WideString> pStr(swSort.GetAt(j));
3110 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( 3114 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
3111 pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID); 3115 pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID);
3112 ASSERT(!pObj.IsEmpty()); 3116 ASSERT(!pObj.IsEmpty());
3113 3117
3114 CJS_Field* pJSField = 3118 CJS_Field* pJSField =
3115 (CJS_Field*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); 3119 static_cast<CJS_Field*>(FXJS_GetPrivate(pRuntime->GetIsolate(), pObj));
3116 Field* pField = (Field*)pJSField->GetEmbedObject(); 3120 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
3117 pField->AttachField(m_pJSDoc, *pStr); 3121 pField->AttachField(m_pJSDoc, *pStr);
3118 3122
3119 CJS_Value FormFieldValue(pRuntime); 3123 CJS_Value FormFieldValue(pRuntime);
3120 FormFieldValue = pJSField; 3124 FormFieldValue = pJSField;
3121 FormFieldArray.SetElement(j, FormFieldValue); 3125 FormFieldArray.SetElement(j++, FormFieldValue);
3122 } 3126 }
3123 3127
3124 vRet = FormFieldArray; 3128 vRet = FormFieldArray;
3125 swSort.RemoveAll();
3126 return TRUE; 3129 return TRUE;
3127 } 3130 }
3128 3131
3129 FX_BOOL Field::getItemAt(IJS_Context* cc, 3132 FX_BOOL Field::getItemAt(IJS_Context* cc,
3130 const std::vector<CJS_Value>& params, 3133 const std::vector<CJS_Value>& params,
3131 CJS_Value& vRet, 3134 CJS_Value& vRet,
3132 CFX_WideString& sError) { 3135 CFX_WideString& sError) {
3133 int iSize = params.size(); 3136 int iSize = params.size();
3134 3137
3135 int nIdx = -1; 3138 int nIdx = -1;
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
3585 } 3588 }
3586 } 3589 }
3587 3590
3588 void Field::AddField(CPDFSDK_Document* pDocument, 3591 void Field::AddField(CPDFSDK_Document* pDocument,
3589 int nPageIndex, 3592 int nPageIndex,
3590 int nFieldType, 3593 int nFieldType,
3591 const CFX_WideString& sName, 3594 const CFX_WideString& sName,
3592 const CPDF_Rect& rcCoords) { 3595 const CPDF_Rect& rcCoords) {
3593 // Not supported. 3596 // Not supported.
3594 } 3597 }
OLDNEW
« 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