diff options
Diffstat (limited to 'src/corelib/tools/qarraydata.h')
| -rw-r--r-- | src/corelib/tools/qarraydata.h | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h index b6fc05e1082..de527133482 100644 --- a/src/corelib/tools/qarraydata.h +++ b/src/corelib/tools/qarraydata.h @@ -306,7 +306,37 @@ namespace QtPrivate { struct Q_CORE_EXPORT QContainerImplHelper { enum CutResult { Null, Empty, Full, Subset }; - static CutResult mid(int originalLength, int *position, int *length); + static constexpr CutResult mid(qsizetype originalLength, qsizetype *_position, qsizetype *_length) + { + qsizetype &position = *_position; + qsizetype &length = *_length; + if (position > originalLength) { + position = 0; + length = 0; + return Null; + } + + if (position < 0) { + if (length < 0 || length + position >= originalLength) { + position = 0; + length = originalLength; + return Full; + } + if (length + position <= 0) { + position = length = 0; + return Null; + } + length += position; + position = 0; + } else if (size_t(length) > size_t(originalLength - position)) { + length = originalLength - position; + } + + if (position == 0 && length == originalLength) + return Full; + + return length > 0 ? Subset : Empty; + } }; } |
