diff options
author | Zufu Liu <unknown> | 2024-12-15 09:11:39 +1100 |
---|---|---|
committer | Zufu Liu <unknown> | 2024-12-15 09:11:39 +1100 |
commit | 8ee5394c1099a410f81e7218cee4a1c6ffaecbdd (patch) | |
tree | 23639aa86f2f075c00a8245bf0dd68307afca602 | |
parent | 49034b8eb1e1dc055b5cb5319948c923c78d63db (diff) | |
download | scintilla-mirror-8ee5394c1099a410f81e7218cee4a1c6ffaecbdd.tar.gz |
Feature [feature-requests:#1537]. Extract common code into function.
-rw-r--r-- | src/AutoComplete.cxx | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/AutoComplete.cxx b/src/AutoComplete.cxx index 57a3073f9..3c7c98cee 100644 --- a/src/AutoComplete.cxx +++ b/src/AutoComplete.cxx @@ -163,21 +163,24 @@ struct Sorter { } }; +void FillSortMatrix(std::vector<int> &sortMatrix, int itemCount) { + sortMatrix.clear(); + for (int i = 0; i < itemCount; i++) { + sortMatrix.push_back(i); + } +} + } void AutoComplete::SetList(const char *list) { if (autoSort == Ordering::PreSorted) { lb->SetList(list, separator, typesep); - sortMatrix.clear(); - for (int i = 0; i < lb->Length(); ++i) - sortMatrix.push_back(i); + FillSortMatrix(sortMatrix, lb->Length()); return; } const Sorter IndexSort(this, list); - sortMatrix.clear(); - for (int i = 0; i < static_cast<int>(IndexSort.indices.size()) / 2; ++i) - sortMatrix.push_back(i); + FillSortMatrix(sortMatrix, static_cast<int>(IndexSort.indices.size() / 2)); std::sort(sortMatrix.begin(), sortMatrix.end(), IndexSort); if (autoSort == Ordering::Custom || sortMatrix.size() < 2) { lb->SetList(list, separator, typesep); @@ -188,6 +191,7 @@ void AutoComplete::SetList(const char *list) { std::string sortedList; for (size_t i = 0; i < sortMatrix.size(); ++i) { const unsigned index = sortMatrix[i] * 2; + sortMatrix[i] = static_cast<int>(i); // word length include trailing typesep and separator const int wordLen = IndexSort.indices[index + 2] - IndexSort.indices[index]; const std::string_view item(list + IndexSort.indices[index], wordLen); @@ -204,8 +208,6 @@ void AutoComplete::SetList(const char *list) { } } } - for (int i = 0; i < static_cast<int>(sortMatrix.size()); ++i) - sortMatrix[i] = i; lb->SetList(sortedList.c_str(), separator, typesep); } |