diff options
author | Andrey Kleshchev <andreykproductengine@lindenlab.com> | 2023-02-03 22:59:50 +0200 |
---|---|---|
committer | Andrey Kleshchev <andreykproductengine@lindenlab.com> | 2023-02-03 22:59:50 +0200 |
commit | 2f4902967ad44c7ca670da11ee05daf8c43a895c (patch) | |
tree | 33774283dfda5f7f594d64ba3800e3f21947f25e /indra/llcommon/llkeybind.cpp | |
parent | c5fcf3066f4a5c75635c774422ff1db59b8624f7 (diff) | |
parent | f3cd329b585ef55a66f2a824f010d1a54d67d8d2 (diff) |
Merge branch 'xcode-14.1' into andreyk/SL-19134
# Conflicts:
# indra/llcommon/llsdserialize.cpp
# indra/llcommon/llsdserialize.h
Diffstat (limited to 'indra/llcommon/llkeybind.cpp')
-rw-r--r-- | indra/llcommon/llkeybind.cpp | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/indra/llcommon/llkeybind.cpp b/indra/llcommon/llkeybind.cpp index 38696c2258..12e57ae94b 100644 --- a/indra/llcommon/llkeybind.cpp +++ b/indra/llcommon/llkeybind.cpp @@ -30,6 +30,7 @@ #include "llsd.h" #include "llsdutil.h" +#include <algorithm> LLKeyData::LLKeyData() : @@ -180,10 +181,10 @@ LLKeyBind::LLKeyBind(const LLSD &key_bind) bool LLKeyBind::operator==(const LLKeyBind& rhs) { - U32 size = mData.size(); + auto size = mData.size(); if (size != rhs.mData.size()) return false; - for (U32 i = 0; i < size; i++) + for (size_t i = 0; i < size; i++) { if (mData[i] != rhs.mData[i]) return false; } @@ -193,7 +194,7 @@ bool LLKeyBind::operator==(const LLKeyBind& rhs) bool LLKeyBind::operator!=(const LLKeyBind& rhs) { - U32 size = mData.size(); + auto size = mData.size(); if (size != rhs.mData.size()) return true; for (U32 i = 0; i < size; i++) @@ -213,19 +214,23 @@ bool LLKeyBind::isEmpty() const return true; } -LLSD LLKeyBind::asLLSD() const +LLKeyBind::data_vector_t::const_iterator LLKeyBind::endNonEmpty() const { - S32 last = mData.size() - 1; - while (mData[last].empty()) - { - last--; - } + // search backwards for last non-empty entry, then turn back into forwards + // iterator (.base() call) + return std::find_if_not(mData.rbegin(), mData.rend(), + [](const auto& kdata){ return kdata.empty(); }).base(); +} +LLSD LLKeyBind::asLLSD() const +{ LLSD data; - for (S32 i = 0; i <= last; ++i) + auto end{ endNonEmpty() }; + for (auto it = mData.begin(); it < end; ++it) { - // append even if empty to not affect visual representation - data.append(mData[i].asLLSD()); + // append intermediate entries even if empty to not affect visual + // representation + data.append(it->asLLSD()); } return data; } @@ -380,16 +385,10 @@ void LLKeyBind::resetKeyData(S32 index) void LLKeyBind::trimEmpty() { - S32 last = mData.size() - 1; - while (last >= 0 && mData[last].empty()) - { - mData.erase(mData.begin() + last); - last--; - } + mData.erase(endNonEmpty(), mData.end()); } -U32 LLKeyBind::getDataCount() +size_t LLKeyBind::getDataCount() { return mData.size(); } - |