Make PDFiumRange moveable
Add an explicit move ctor to PDFiumRange, and use it in PDFiumEngine::AddFindResult() to avoid copying. Also add move/copy operator= to match the move/copy ctors. Change-Id: Ia912938101120fb0027a50defcb5d3dd34fa6306 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5888525 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Alan Screen <awscreen@chromium.org> Cr-Commit-Position: refs/heads/main@{#1359998}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
9cde337915
commit
1c03a730ad
@ -1805,6 +1805,8 @@ void PDFiumEngine::StartFind(const std::u16string& text, bool case_sensitive) {
|
||||
bool first_search = (current_find_text_ != text);
|
||||
int character_to_start_searching_from = 0;
|
||||
if (first_search) {
|
||||
// Do not move `selection_` here, as StopFind() expects to start with the
|
||||
// existing selection.
|
||||
std::vector<PDFiumRange> old_selection = selection_;
|
||||
StopFind();
|
||||
current_find_text_ = text;
|
||||
@ -1906,7 +1908,7 @@ void PDFiumEngine::SearchUsingPDFium(const std::u16string& term,
|
||||
break;
|
||||
}
|
||||
|
||||
AddFindResult(result);
|
||||
AddFindResult(std::move(result));
|
||||
}
|
||||
|
||||
FPDFText_FindClose(find);
|
||||
@ -2044,7 +2046,7 @@ void PDFiumEngine::SearchUsingICU(const std::u16string& term,
|
||||
}
|
||||
}
|
||||
|
||||
void PDFiumEngine::AddFindResult(const PDFiumRange& result) {
|
||||
void PDFiumEngine::AddFindResult(PDFiumRange result) {
|
||||
// Figure out where to insert the new location, since we could have
|
||||
// started searching midway and now we wrapped.
|
||||
size_t result_index;
|
||||
@ -2057,7 +2059,7 @@ void PDFiumEngine::AddFindResult(const PDFiumRange& result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
find_results_.insert(find_results_.begin() + result_index, result);
|
||||
find_results_.insert(find_results_.begin() + result_index, std::move(result));
|
||||
UpdateTickMarks();
|
||||
client_->NotifyNumberOfFindResultsChanged(find_results_.size(), false);
|
||||
}
|
||||
|
@ -602,7 +602,7 @@ class PDFiumEngine : public DocumentLoader::Client, public IFSDK_PAUSE {
|
||||
void ContinueFind(bool case_sensitive);
|
||||
|
||||
// Inserts a find result into `find_results_`, which is sorted.
|
||||
void AddFindResult(const PDFiumRange& result);
|
||||
void AddFindResult(PDFiumRange result);
|
||||
|
||||
// Search a page using PDFium's methods. Doesn't work with unicode. This
|
||||
// function is just kept arount in case PDFium code is fixed.
|
||||
|
@ -47,7 +47,13 @@ PDFiumRange::PDFiumRange(PDFiumPage* page, int char_index, int char_count)
|
||||
#endif
|
||||
}
|
||||
|
||||
PDFiumRange::PDFiumRange(const PDFiumRange& that) = default;
|
||||
PDFiumRange::PDFiumRange(const PDFiumRange&) = default;
|
||||
|
||||
PDFiumRange& PDFiumRange::operator=(const PDFiumRange&) = default;
|
||||
|
||||
PDFiumRange::PDFiumRange(PDFiumRange&&) noexcept = default;
|
||||
|
||||
PDFiumRange& PDFiumRange::operator=(PDFiumRange&&) noexcept = default;
|
||||
|
||||
PDFiumRange::~PDFiumRange() = default;
|
||||
|
||||
|
@ -28,7 +28,10 @@ bool IsIgnorableCharacter(char16_t c);
|
||||
class PDFiumRange {
|
||||
public:
|
||||
PDFiumRange(PDFiumPage* page, int char_index, int char_count);
|
||||
PDFiumRange(const PDFiumRange& that);
|
||||
PDFiumRange(const PDFiumRange&);
|
||||
PDFiumRange& operator=(const PDFiumRange&);
|
||||
PDFiumRange(PDFiumRange&&) noexcept;
|
||||
PDFiumRange& operator=(PDFiumRange&&) noexcept;
|
||||
~PDFiumRange();
|
||||
|
||||
// Update how many characters are in the selection. Could be negative if
|
||||
|
Reference in New Issue
Block a user