diff options
author | janwillem32 <janwillem32@users.sourceforge.net> | 2012-06-16 02:05:06 +0400 |
---|---|---|
committer | janwillem32 <janwillem32@users.sourceforge.net> | 2012-06-16 02:05:06 +0400 |
commit | 4e77d4e4e9a302282a385724870db9cd1538a5f9 (patch) | |
tree | f2bd2a05ea86898b24f84d295712a71320713cb1 | |
parent | a881a35a66f37298c448391d2295ed5f0d62d39b (diff) |
DSMPropertyBag.h, range_bsearch: extended the valid range to MAXSIZE_T - 1, made the loop work with unsigned values for i, j and mid (partially to avoid a currently present warning) and added the regular declspec and inlining attributes.
The related files were updated to handle the unsigned return values from range_bsearch.
This commit fixes ticket #2381.
git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@5145 10f7b99b-c216-0410-bff0-8a66a9350fd8
-rw-r--r-- | src/DSUtil/DSMPropertyBag.cpp | 15 | ||||
-rw-r--r-- | src/DSUtil/DSMPropertyBag.h | 25 | ||||
-rw-r--r-- | src/filters/parser/DSMSplitter/DSMSplitterFile.cpp | 4 |
3 files changed, 24 insertions, 20 deletions
diff --git a/src/DSUtil/DSMPropertyBag.cpp b/src/DSUtil/DSMPropertyBag.cpp index c292cf282..6b9c5b4ee 100644 --- a/src/DSUtil/DSMPropertyBag.cpp +++ b/src/DSUtil/DSMPropertyBag.cpp @@ -440,16 +440,13 @@ STDMETHODIMP_(long) IDSMChapterBagImpl::ChapLookup(REFERENCE_TIME* prt, BSTR* pp ChapSort();
- ptrdiff_t i = range_bsearch(m_chapters, *prt);
- if (i < 0) {
- return -1;
- }
-
- *prt = m_chapters[i].rt;
- if (ppName) {
- *ppName = m_chapters[i].name.AllocSysString();
+ size_t i = range_bsearch(m_chapters, *prt);
+ if (i != MAXSIZE_T) {
+ *prt = m_chapters[i].rt;
+ if (ppName) {
+ *ppName = m_chapters[i].name.AllocSysString();
+ }
}
-
return (long)i;
}
diff --git a/src/DSUtil/DSMPropertyBag.h b/src/DSUtil/DSMPropertyBag.h index 61f97a37f..4288e8991 100644 --- a/src/DSUtil/DSMPropertyBag.h +++ b/src/DSUtil/DSMPropertyBag.h @@ -184,20 +184,27 @@ public: };
template<class T>
-ptrdiff_t range_bsearch(CAtlArray<T> const& tArray, REFERENCE_TIME rt)
+__declspec(nothrow noalias) __forceinline size_t range_bsearch(CAtlArray<T> const& tArray, REFERENCE_TIME rt)
{
- ptrdiff_t i = 0, j = tArray.GetCount() - 1, ret = -1;
- if (j >= 0 && rt >= tArray[j].rt) {
- return j;
+ // MAXSIZE_T is returned by this function for status invalid
+ ptrdiff_t k = tArray.GetCount() - 1;
+ if ((k < 0) || (rt >= tArray[k].rt)) {
+ return k;
}
- while (i < j) {
- size_t mid = static_cast<size_t>(i + j) >> 1;
+ size_t ret = MAXSIZE_T;
+ if (!k) {
+ return ret;
+ }
+
+ size_t i = 0, j = k;
+ do {
+ size_t mid = (i + j) >> 1;
REFERENCE_TIME midrt = tArray[mid].rt;
if (rt == midrt) {
ret = mid;
break;
} else if (rt < midrt) {
- ret = -1;
+ ret = MAXSIZE_T;
if (j == mid) {
--mid;
}
@@ -209,6 +216,6 @@ ptrdiff_t range_bsearch(CAtlArray<T> const& tArray, REFERENCE_TIME rt) }
i = mid;
}
- }
- return ret;// in general, the return is unsigned, only when tArray is empty, the return will be -1 for status invalid
+ } while (i < j);
+ return ret;
}
diff --git a/src/filters/parser/DSMSplitter/DSMSplitterFile.cpp b/src/filters/parser/DSMSplitter/DSMSplitterFile.cpp index fb47c6139..3a0acf454 100644 --- a/src/filters/parser/DSMSplitter/DSMSplitterFile.cpp +++ b/src/filters/parser/DSMSplitter/DSMSplitterFile.cpp @@ -309,8 +309,8 @@ __int64 CDSMSplitterFile::Read(__int64 len, CStringW& str) __int64 CDSMSplitterFile::FindSyncPoint(REFERENCE_TIME rt)
{
if (/*!m_sps.IsEmpty()*/ m_sps.GetCount() > 1) {
- ptrdiff_t i = range_bsearch(m_sps, m_rtFirst + rt);
- return i >= 0 ? m_sps[i].fp : 0;
+ size_t i = range_bsearch(m_sps, m_rtFirst + rt);
+ return (i != MAXSIZE_T) ? m_sps[i].fp : 0;
}
if (m_rtDuration <= 0 || rt <= m_rtFirst) {
|