Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/miloyip/rapidjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorylavic <ylavic.dev@gmail.com>2018-12-11 02:40:05 +0300
committerylavic <ylavic.dev@gmail.com>2018-12-12 17:15:43 +0300
commit0e34ed43f40fa522de4e88e3d817882cef3b6c40 (patch)
treef3a2f31f6a78fc9ecc26085e1af9951a02fc7a78 /include/rapidjson/pointer.h
parentaf17f196c69bb3a7ff86f6709574fabf41b79805 (diff)
Rework Pointer::operator<() loop.
I must be too dumb to understand the mess MSVC (32bit only) did with the previous loop, and to figure out how it might have make it never end. Anyway, hopefully any compiler can grok this new loop...
Diffstat (limited to 'include/rapidjson/pointer.h')
-rw-r--r--include/rapidjson/pointer.h31
1 files changed, 12 insertions, 19 deletions
diff --git a/include/rapidjson/pointer.h b/include/rapidjson/pointer.h
index 54a8c9aa..97a376a5 100644
--- a/include/rapidjson/pointer.h
+++ b/include/rapidjson/pointer.h
@@ -358,7 +358,7 @@ public:
//! Less than operator.
/*!
- \note Invalid pointers are never lesser than valid ones.
+ \note Invalid pointers are always greater than valid ones.
*/
bool operator<(const GenericPointer& rhs) const {
if (!IsValid())
@@ -366,27 +366,20 @@ public:
if (!rhs.IsValid())
return true;
- size_t i = 0, lCount = tokenCount_, rCount = rhs.tokenCount_;
- for (;;) {
- if (!rCount)
- return false;
- if (!lCount)
- return true;
-
- if (tokens_[i].index != rhs.tokens_[i].index)
- return tokens_[i].index < rhs.tokens_[i].index;
+ const Token *lTok = tokens_, *const lEnd = lTok + tokenCount_,
+ *rTok = rhs.tokens_, *const rEnd = rTok + rhs.tokenCount_;
+ for (; lTok != lEnd && rTok != rEnd; ++lTok, ++rTok) {
+ if (lTok->index != rTok->index)
+ return lTok->index < rTok->index;
- if (tokens_[i].length > rhs.tokens_[i].length)
- return std::memcmp(tokens_[i].name, rhs.tokens_[i].name, sizeof(Ch) * rhs.tokens_[i].length) < 0;
+ if (lTok->length > rTok->length)
+ return std::memcmp(lTok->name, rTok->name, sizeof(Ch) * rTok->length) < 0;
- int cmp = std::memcmp(tokens_[i].name, rhs.tokens_[i].name, sizeof(Ch) * tokens_[i].length);
- if (cmp || tokens_[i].length != rhs.tokens_[i].length)
- return cmp <= 0;
-
- lCount--;
- rCount--;
- i++;
+ int comp = std::memcmp(lTok->name, rTok->name, sizeof(Ch) * lTok->length);
+ if (comp || lTok->length != rTok->length)
+ return comp <= 0;
}
+ return rTok != rEnd;
}
//@}