Avoid c_str() then strlen() in view constructor in CFWL_ComboList.
Change-Id: Iec6e28e8d17d05602c19d7ed79d77a73c0a79004
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/61771
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 2ed36b8..7c77fc5 100644
--- a/xfa/fwl/cfwl_combobox.cpp
+++ b/xfa/fwl/cfwl_combobox.cpp
@@ -261,7 +261,7 @@
void CFWL_ComboBox::MatchEditText() {
WideString wsText = m_pEdit->GetText();
- int32_t iMatch = m_pListBox->MatchItem(wsText);
+ int32_t iMatch = m_pListBox->MatchItem(wsText.AsStringView());
if (iMatch != m_iCurSel) {
m_pListBox->ChangeSelected(iMatch);
if (iMatch >= 0)
@@ -558,7 +558,7 @@
int32_t iCurSel = m_iCurSel;
if (m_pEdit) {
WideString wsText = m_pEdit->GetText();
- iCurSel = pComboList->MatchItem(wsText);
+ iCurSel = pComboList->MatchItem(wsText.AsStringView());
if (iCurSel >= 0) {
CFWL_ListItem* item = m_pListBox->GetSelItem(iCurSel);
bMatchEqual = wsText == (item ? item->GetText() : WideString());
diff --git a/xfa/fwl/cfwl_combolist.cpp b/xfa/fwl/cfwl_combolist.cpp
index 65d400f..7c30bdf 100644
--- a/xfa/fwl/cfwl_combolist.cpp
+++ b/xfa/fwl/cfwl_combolist.cpp
@@ -25,7 +25,7 @@
ASSERT(pOuter);
}
-int32_t CFWL_ComboList::MatchItem(const WideString& wsMatch) {
+int32_t CFWL_ComboList::MatchItem(WideStringView wsMatch) {
if (wsMatch.IsEmpty())
return -1;
@@ -33,7 +33,7 @@
for (int32_t i = 0; i < iCount; i++) {
CFWL_ListItem* hItem = GetItem(this, i);
WideString wsText = hItem ? hItem->GetText() : WideString();
- auto pos = wsText.Find(wsMatch.c_str());
+ auto pos = wsText.Find(wsMatch);
if (pos.has_value() && pos.value() == 0)
return i;
}
diff --git a/xfa/fwl/cfwl_combolist.h b/xfa/fwl/cfwl_combolist.h
index 0444a93..24a1012 100644
--- a/xfa/fwl/cfwl_combolist.h
+++ b/xfa/fwl/cfwl_combolist.h
@@ -22,10 +22,8 @@
// CFWL_ListBox.
void OnProcessMessage(CFWL_Message* pMessage) override;
- int32_t MatchItem(const WideString& wsMatch);
-
+ int32_t MatchItem(WideStringView wsMatch);
void ChangeSelected(int32_t iSel);
-
void SetNotifyOwner(bool notify) { m_bNotifyOwner = notify; }
private: