Prevent duplicate string creation in CFWL_ComboBox::AddString() Change-Id: Id2baf98c52aa5fcc9e1dd744187318bcb67ac081 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/61770 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fwl/cfwl_combobox.cpp b/xfa/fwl/cfwl_combobox.cpp index 808c8c2..2ed36b8 100644 --- a/xfa/fwl/cfwl_combobox.cpp +++ b/xfa/fwl/cfwl_combobox.cpp
@@ -43,7 +43,7 @@ return FWL_Type::ComboBox; } -void CFWL_ComboBox::AddString(WideStringView wsText) { +void CFWL_ComboBox::AddString(const WideString& wsText) { m_pListBox->AddString(wsText); }
diff --git a/xfa/fwl/cfwl_combobox.h b/xfa/fwl/cfwl_combobox.h index 4142b83..ce3414b 100644 --- a/xfa/fwl/cfwl_combobox.h +++ b/xfa/fwl/cfwl_combobox.h
@@ -59,7 +59,7 @@ int32_t GetCurSel() const { return m_iCurSel; } void SetCurSel(int32_t iSel); - void AddString(WideStringView wsText); + void AddString(const WideString& wsText); void RemoveAt(int32_t iIndex); void RemoveAll();
diff --git a/xfa/fwl/cfwl_listbox.cpp b/xfa/fwl/cfwl_listbox.cpp index 4de06db..b2b0f2e 100644 --- a/xfa/fwl/cfwl_listbox.cpp +++ b/xfa/fwl/cfwl_listbox.cpp
@@ -901,9 +901,8 @@ return it != m_ItemArray.end() ? it - m_ItemArray.begin() : -1; } -CFWL_ListItem* CFWL_ListBox::AddString(WideStringView wsAdd) { - m_ItemArray.emplace_back( - pdfium::MakeUnique<CFWL_ListItem>(WideString(wsAdd))); +CFWL_ListItem* CFWL_ListBox::AddString(const WideString& wsAdd) { + m_ItemArray.emplace_back(pdfium::MakeUnique<CFWL_ListItem>(wsAdd)); return m_ItemArray.back().get(); }
diff --git a/xfa/fwl/cfwl_listbox.h b/xfa/fwl/cfwl_listbox.h index 9d3a21a..178e49a 100644 --- a/xfa/fwl/cfwl_listbox.h +++ b/xfa/fwl/cfwl_listbox.h
@@ -53,7 +53,7 @@ CFWL_ListItem* GetItem(const CFWL_Widget* pWidget, int32_t nIndex) const; int32_t GetItemIndex(CFWL_Widget* pWidget, CFWL_ListItem* pItem); - CFWL_ListItem* AddString(WideStringView wsAdd); + CFWL_ListItem* AddString(const WideString& wsAdd); void RemoveAt(int32_t iIndex); void DeleteString(CFWL_ListItem* pItem); void DeleteAll();
diff --git a/xfa/fxfa/cxfa_ffcombobox.cpp b/xfa/fxfa/cxfa_ffcombobox.cpp index 2efbdf8..6093bb1 100644 --- a/xfa/fxfa/cxfa_ffcombobox.cpp +++ b/xfa/fxfa/cxfa_ffcombobox.cpp
@@ -56,7 +56,7 @@ m_pNormalWidget->LockUpdate(); for (const auto& label : m_pNode->GetChoiceListItems(false)) - pComboBox->AddString(label.AsStringView()); + pComboBox->AddString(label); std::vector<int32_t> iSelArray = m_pNode->GetSelectedItems(); if (iSelArray.empty()) @@ -280,7 +280,7 @@ InvalidateRect(); } -void CXFA_FFComboBox::InsertItem(WideStringView wsLabel, int32_t nIndex) { +void CXFA_FFComboBox::InsertItem(const WideString& wsLabel, int32_t nIndex) { ToComboBox(m_pNormalWidget.get())->AddString(wsLabel); m_pNormalWidget->Update(); InvalidateRect();
diff --git a/xfa/fxfa/cxfa_ffcombobox.h b/xfa/fxfa/cxfa_ffcombobox.h index 78b7eb5..5396cdf 100644 --- a/xfa/fxfa/cxfa_ffcombobox.h +++ b/xfa/fxfa/cxfa_ffcombobox.h
@@ -48,7 +48,7 @@ const CFX_Matrix& matrix) override; // CXFA_FFDropDown - void InsertItem(WideStringView wsLabel, int32_t nIndex) override; + void InsertItem(const WideString& wsLabel, int32_t nIndex) override; void DeleteItem(int32_t nIndex) override; void OpenDropDownList();
diff --git a/xfa/fxfa/cxfa_ffdropdown.h b/xfa/fxfa/cxfa_ffdropdown.h index f2288df..26446bc 100644 --- a/xfa/fxfa/cxfa_ffdropdown.h +++ b/xfa/fxfa/cxfa_ffdropdown.h
@@ -7,13 +7,14 @@ #ifndef XFA_FXFA_CXFA_FFDROPDOWN_H_ #define XFA_FXFA_CXFA_FFDROPDOWN_H_ +#include "core/fxcrt/widestring.h" #include "xfa/fxfa/cxfa_fffield.h" class CXFA_FFDropDown : public CXFA_FFField { public: ~CXFA_FFDropDown() override; - virtual void InsertItem(WideStringView wsLabel, int32_t nIndex) = 0; + virtual void InsertItem(const WideString& wsLabel, int32_t nIndex) = 0; virtual void DeleteItem(int32_t nIndex) = 0; protected:
diff --git a/xfa/fxfa/cxfa_fflistbox.cpp b/xfa/fxfa/cxfa_fflistbox.cpp index 4643de3..349f749 100644 --- a/xfa/fxfa/cxfa_fflistbox.cpp +++ b/xfa/fxfa/cxfa_fflistbox.cpp
@@ -56,7 +56,7 @@ m_pNormalWidget->LockUpdate(); for (const auto& label : m_pNode->GetChoiceListItems(false)) - pListBox->AddString(label.AsStringView()); + pListBox->AddString(label); uint32_t dwExtendedStyle = FWL_STYLEEXT_LTB_ShowScrollBarFocus; if (m_pNode->IsChoiceListMultiSelect()) @@ -164,9 +164,8 @@ InvalidateRect(); } -void CXFA_FFListBox::InsertItem(WideStringView wsLabel, int32_t nIndex) { - WideString wsTemp(wsLabel); - ToListBox(m_pNormalWidget.get())->AddString(wsTemp.AsStringView()); +void CXFA_FFListBox::InsertItem(const WideString& wsLabel, int32_t nIndex) { + ToListBox(m_pNormalWidget.get())->AddString(wsLabel); m_pNormalWidget->Update(); InvalidateRect(); }
diff --git a/xfa/fxfa/cxfa_fflistbox.h b/xfa/fxfa/cxfa_fflistbox.h index f9fa801..896ee61 100644 --- a/xfa/fxfa/cxfa_fflistbox.h +++ b/xfa/fxfa/cxfa_fflistbox.h
@@ -25,7 +25,7 @@ FormFieldType GetFormFieldType() override; // CXFA_FFDropDown - void InsertItem(WideStringView wsLabel, int32_t nIndex) override; + void InsertItem(const WideString& wsLabel, int32_t nIndex) override; void DeleteItem(int32_t nIndex) override; void OnSelectChanged(CFWL_Widget* pWidget);
diff --git a/xfa/fxfa/cxfa_ffnotify.cpp b/xfa/fxfa/cxfa_ffnotify.cpp index e034dc9..a71a3a5 100644 --- a/xfa/fxfa/cxfa_ffnotify.cpp +++ b/xfa/fxfa/cxfa_ffnotify.cpp
@@ -75,7 +75,7 @@ CXFA_FFWidget* pWidget = m_pDoc->GetDocView()->GetWidgetForNode(pSender); for (; pWidget; pWidget = pSender->GetNextWidget(pWidget)) { if (pWidget->IsLoaded()) - ToDropDown(pWidget)->InsertItem(wsLabel.AsStringView(), iIndex); + ToDropDown(pWidget)->InsertItem(wsLabel, iIndex); } }