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

github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2017-08-13 19:34:51 +0300
committerKacper Michajłow <kasper93@gmail.com>2017-08-13 23:24:43 +0300
commit560be8be9f5aa4738b9d25c40639b4427157d9b6 (patch)
treef5c62e88810f4c1c19a49036c6d1372c7e5421cd
parentfe9d00c292419dc67849bd063812d8bb44feeb6d (diff)
Replace all qsort with std::sort.
-rw-r--r--src/DSUtil/DSMPropertyBag.cpp18
-rw-r--r--src/DSUtil/DSMPropertyBag.h7
-rw-r--r--src/Subtitles/STS.cpp19
-rw-r--r--src/Subtitles/SubtitleHelpers.cpp7
-rw-r--r--src/Subtitles/SubtitleHelpers.h6
-rw-r--r--src/Subtitles/VobSubFile.h6
-rw-r--r--src/Subtitles/VobSubFileRipper.cpp9
-rw-r--r--src/filters/parser/DSMSplitter/DSMSplitter.cpp9
-rw-r--r--src/mpc-hc/FGFilter.cpp52
-rw-r--r--src/mpc-hc/FGFilter.h38
-rw-r--r--src/mpc-hc/PlayerSubresyncBar.cpp11
-rw-r--r--src/mpc-hc/Playlist.cpp32
12 files changed, 86 insertions, 128 deletions
diff --git a/src/DSUtil/DSMPropertyBag.cpp b/src/DSUtil/DSMPropertyBag.cpp
index da29eabfd..17fe91ccf 100644
--- a/src/DSUtil/DSMPropertyBag.cpp
+++ b/src/DSUtil/DSMPropertyBag.cpp
@@ -1,6 +1,6 @@
/*
* (C) 2003-2006 Gabest
- * (C) 2006-2014 see Authors.txt
+ * (C) 2006-2014, 2017 see Authors.txt
*
* This file is part of MPC-HC.
*
@@ -342,20 +342,6 @@ CDSMChapter& CDSMChapter::operator = (const CDSMChapter& c)
int CDSMChapter::counter = 0;
-int CDSMChapter::Compare(const void* a, const void* b)
-{
- const CDSMChapter* ca = static_cast<const CDSMChapter*>(a);
- const CDSMChapter* cb = static_cast<const CDSMChapter*>(b);
-
- if (ca->rt > cb->rt) {
- return 1;
- } else if (ca->rt < cb->rt) {
- return -1;
- }
-
- return ca->order - cb->order;
-}
-
//
// IDSMChapterBagImpl
//
@@ -454,7 +440,7 @@ STDMETHODIMP IDSMChapterBagImpl::ChapSort()
if (m_fSorted) {
return S_FALSE;
}
- qsort(m_chapters.GetData(), m_chapters.GetCount(), sizeof(CDSMChapter), CDSMChapter::Compare);
+ std::sort(m_chapters.GetData(), m_chapters.GetData() + m_chapters.GetCount());
m_fSorted = true;
return S_OK;
}
diff --git a/src/DSUtil/DSMPropertyBag.h b/src/DSUtil/DSMPropertyBag.h
index 9d14cf7b4..dae83829e 100644
--- a/src/DSUtil/DSMPropertyBag.h
+++ b/src/DSUtil/DSMPropertyBag.h
@@ -1,6 +1,6 @@
/*
* (C) 2003-2006 Gabest
- * (C) 2006-2013 see Authors.txt
+ * (C) 2006-2013, 2017 see Authors.txt
*
* This file is part of MPC-HC.
*
@@ -150,7 +150,10 @@ public:
CDSMChapter();
CDSMChapter(REFERENCE_TIME rt, LPCWSTR name);
CDSMChapter& operator = (const CDSMChapter& c);
- static int Compare(const void* a, const void* b);
+
+ bool operator <(const CDSMChapter& rhs) const {
+ return (rt != rhs.rt) ? rt < rhs.rt : order < rhs.order;
+ }
};
class IDSMChapterBagImpl : public IDSMChapterBag
diff --git a/src/Subtitles/STS.cpp b/src/Subtitles/STS.cpp
index a7839c79b..902d8a28d 100644
--- a/src/Subtitles/STS.cpp
+++ b/src/Subtitles/STS.cpp
@@ -2520,26 +2520,25 @@ void CSimpleTextSubtitle::SetStr(int i, CStringW str, bool fUnicode)
}
}
-static int comp1(const void* a, const void* b)
+static inline bool comp1(const STSEntry& lhs, const STSEntry& rhs)
{
- int ret = SGN(((STSEntry*)a)->start - ((STSEntry*)b)->start);
- if (ret == 0) {
- ret = ((STSEntry*)a)->layer - ((STSEntry*)b)->layer;
+ if (lhs.start != rhs.start) {
+ return lhs.start < rhs.start;
}
- if (ret == 0) {
- ret = ((STSEntry*)a)->readorder - ((STSEntry*)b)->readorder;
+ if (lhs.layer != rhs.layer) {
+ return lhs.layer < rhs.layer;
}
- return ret;
+ return lhs.readorder < rhs.readorder;
}
-static int comp2(const void* a, const void* b)
+static inline bool comp2(const STSEntry& lhs, const STSEntry& rhs)
{
- return (((STSEntry*)a)->readorder - ((STSEntry*)b)->readorder);
+ return lhs.readorder < rhs.readorder;
}
void CSimpleTextSubtitle::Sort(bool fRestoreReadorder)
{
- qsort(GetData(), GetCount(), sizeof(STSEntry), !fRestoreReadorder ? comp1 : comp2);
+ std::sort(GetData(), GetData() + GetCount(), !fRestoreReadorder ? comp1 : comp2);
CreateSegments();
}
diff --git a/src/Subtitles/SubtitleHelpers.cpp b/src/Subtitles/SubtitleHelpers.cpp
index 17f91e266..4aea67ad9 100644
--- a/src/Subtitles/SubtitleHelpers.cpp
+++ b/src/Subtitles/SubtitleHelpers.cpp
@@ -36,11 +36,6 @@ namespace
LPCTSTR separators = _T(".\\-_");
LPCTSTR extListVid = _T("(avi)|(mkv)|(mp4)|((m2)?ts)");
-
- int SubFileCompare(const void* elem1, const void* elem2)
- {
- return ((Subtitle::SubFile*)elem1)->fn.CompareNoCase(((Subtitle::SubFile*)elem2)->fn);
- }
}
LPCTSTR Subtitle::GetSubtitleFileExt(SubType type)
@@ -169,7 +164,7 @@ void Subtitle::GetSubFileNames(CString fn, const CAtlArray<CString>& paths, CAtl
// sort files, this way the user can define the order (movie.00.English.srt, movie.01.Hungarian.srt, etc)
- qsort(ret.GetData(), ret.GetCount(), sizeof(SubFile), SubFileCompare);
+ std::sort(ret.GetData(), ret.GetData() + ret.GetCount());
}
CString Subtitle::GuessSubtitleName(const CString& fn, CString videoName, LCID& lcid, HearingImpairedType& hi)
diff --git a/src/Subtitles/SubtitleHelpers.h b/src/Subtitles/SubtitleHelpers.h
index 95b9beec0..cdb6a94b9 100644
--- a/src/Subtitles/SubtitleHelpers.h
+++ b/src/Subtitles/SubtitleHelpers.h
@@ -1,6 +1,6 @@
/*
* (C) 2003-2006 Gabest
- * (C) 2006-2016 see Authors.txt
+ * (C) 2006-2017 see Authors.txt
*
* This file is part of MPC-HC.
*
@@ -56,6 +56,10 @@ namespace Subtitle
struct SubFile {
CString fn; /*SubType type;*/
+
+ bool operator <(const SubFile& rhs) const {
+ return fn.CompareNoCase(rhs.fn) < 0;
+ }
};
void GetSubFileNames(CString fn, const CAtlArray<CString>& paths, CAtlArray<SubFile>& ret);
diff --git a/src/Subtitles/VobSubFile.h b/src/Subtitles/VobSubFile.h
index b1aea10e1..16765135a 100644
--- a/src/Subtitles/VobSubFile.h
+++ b/src/Subtitles/VobSubFile.h
@@ -1,6 +1,6 @@
/*
* (C) 2003-2006 Gabest
- * (C) 2006-2015 see Authors.txt
+ * (C) 2006-2015, 2017 see Authors.txt
*
* This file is part of MPC-HC.
*
@@ -91,6 +91,10 @@ public:
char cellid = 0;
__int64 celltimestamp = 0i64;
bool bValid = false;
+
+ bool operator <(const SubPos& rhs) const {
+ return start < rhs.start;
+ }
};
struct SubLang {
diff --git a/src/Subtitles/VobSubFileRipper.cpp b/src/Subtitles/VobSubFileRipper.cpp
index f79ab0fa9..398b90649 100644
--- a/src/Subtitles/VobSubFileRipper.cpp
+++ b/src/Subtitles/VobSubFileRipper.cpp
@@ -1,6 +1,6 @@
/*
* (C) 2003-2006 Gabest
- * (C) 2006-2016 see Authors.txt
+ * (C) 2006-2017 see Authors.txt
*
* This file is part of MPC-HC.
*
@@ -455,11 +455,6 @@ DWORD CVobSubFileRipper::ThreadProc()
#pragma warning(pop)
}
-static int SubPosSortProc(const void* e1, const void* e2)
-{
- return ((int)(((CVobSubFile::SubPos*)e1)->start - ((CVobSubFile::SubPos*)e2)->start));
-}
-
bool CVobSubFileRipper::Create()
{
CAutoLock cAutoLock(&m_csAccessLock);
@@ -777,7 +772,7 @@ bool CVobSubFileRipper::Create()
m_langs[i].name = m_langs[i].alt = FindLangFromId(m_langs[i].id);
CAtlArray<SubPos>& sp = m_langs[i].subpos;
- qsort(sp.GetData(), sp.GetCount(), sizeof(SubPos), SubPosSortProc);
+ std::sort(sp.GetData(), sp.GetData() + sp.GetCount());
if (m_rd.bForcedOnly) {
Log(LOG_INFO, _T("Searching for forced subs..."));
diff --git a/src/filters/parser/DSMSplitter/DSMSplitter.cpp b/src/filters/parser/DSMSplitter/DSMSplitter.cpp
index b799c99bd..d9a00b855 100644
--- a/src/filters/parser/DSMSplitter/DSMSplitter.cpp
+++ b/src/filters/parser/DSMSplitter/DSMSplitter.cpp
@@ -1,6 +1,6 @@
/*
* (C) 2003-2006 Gabest
- * (C) 2006-2013, 2016 see Authors.txt
+ * (C) 2006-2013, 2016-2017 see Authors.txt
*
* This file is part of MPC-HC.
*
@@ -111,11 +111,6 @@ STDMETHODIMP CDSMSplitterFilter::QueryFilterInfo(FILTER_INFO* pInfo)
return S_OK;
}
-static int compare_id(const void* id1, const void* id2)
-{
- return (int) * (BYTE*)id1 - (int) * (BYTE*)id2;
-}
-
HRESULT CDSMSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
{
CheckPointer(pAsyncReader, E_POINTER);
@@ -145,7 +140,7 @@ HRESULT CDSMSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
ids.Add(id);
}
- qsort(ids.GetData(), ids.GetCount(), sizeof(BYTE), compare_id);
+ std::sort(ids.GetData(), ids.GetData() + ids.GetCount());
for (size_t i = 0; i < ids.GetCount(); i++) {
BYTE id = ids[i];
diff --git a/src/mpc-hc/FGFilter.cpp b/src/mpc-hc/FGFilter.cpp
index c4f544e55..6ac3b7f70 100644
--- a/src/mpc-hc/FGFilter.cpp
+++ b/src/mpc-hc/FGFilter.cpp
@@ -1,6 +1,6 @@
/*
* (C) 2003-2006 Gabest
- * (C) 2006-2016 see Authors.txt
+ * (C) 2006-2017 see Authors.txt
*
* This file is part of MPC-HC.
*
@@ -604,7 +604,7 @@ POSITION CFGFilterList::GetHeadPosition()
for (int i = 0; pos; i++) {
sort[i] = m_filters.GetNext(pos);
}
- qsort(&sort[0], sort.GetCount(), sizeof(sort[0]), filter_cmp);
+ std::sort(sort.GetData(), sort.GetData() + sort.GetCount());
for (size_t i = 0; i < sort.GetCount(); i++) {
if (sort[i].pFGF->GetMerit() >= MERIT64_DO_USE) {
m_sortedfilters.AddTail(sort[i].pFGF);
@@ -629,51 +629,3 @@ CFGFilter* CFGFilterList::GetNext(POSITION& pos)
{
return m_sortedfilters.GetNext(pos);
}
-
-int CFGFilterList::filter_cmp(const void* a, const void* b)
-{
- filter_t* fa = (filter_t*)a;
- filter_t* fb = (filter_t*)b;
-
- if (fa->group < fb->group) {
- return -1;
- }
- if (fa->group > fb->group) {
- return +1;
- }
-
- if (fa->pFGF->GetMerit() > fb->pFGF->GetMerit()) {
- return -1;
- }
- if (fa->pFGF->GetMerit() < fb->pFGF->GetMerit()) {
- return +1;
- }
-
- if (fa->pFGF->GetCLSID() == fb->pFGF->GetCLSID()) {
- CFGFilterFile* fgfa = dynamic_cast<CFGFilterFile*>(fa->pFGF);
- CFGFilterFile* fgfb = dynamic_cast<CFGFilterFile*>(fb->pFGF);
-
- if (fgfa && !fgfb) {
- return -1;
- }
- if (!fgfa && fgfb) {
- return +1;
- }
- }
-
- if (fa->exactmatch && !fb->exactmatch) {
- return -1;
- }
- if (!fa->exactmatch && fb->exactmatch) {
- return +1;
- }
-
- if (fa->index < fb->index) {
- return -1;
- }
- if (fa->index > fb->index) {
- return +1;
- }
-
- return 0;
-}
diff --git a/src/mpc-hc/FGFilter.h b/src/mpc-hc/FGFilter.h
index a0c035bab..143875fcb 100644
--- a/src/mpc-hc/FGFilter.h
+++ b/src/mpc-hc/FGFilter.h
@@ -1,6 +1,6 @@
/*
* (C) 2003-2006 Gabest
- * (C) 2006-2013, 2015 see Authors.txt
+ * (C) 2006-2013, 2015, 2017 see Authors.txt
*
* This file is part of MPC-HC.
*
@@ -140,8 +140,42 @@ class CFGFilterList
CFGFilter* pFGF;
int group;
bool exactmatch, autodelete;
+
+ bool operator <(const filter_t& rhs) const {
+ if (group != rhs.group) {
+ return group < rhs.group;
+ }
+
+ if (pFGF->GetMerit() != rhs.pFGF->GetMerit()) {
+ return pFGF->GetMerit() > rhs.pFGF->GetMerit();
+ }
+
+ if (pFGF->GetCLSID() == rhs.pFGF->GetCLSID()) {
+ CFGFilterFile* fgfa = dynamic_cast<CFGFilterFile*>(pFGF);
+ CFGFilterFile* fgfb = dynamic_cast<CFGFilterFile*>(rhs.pFGF);
+
+ if (fgfa && !fgfb) {
+ return true;
+ }
+ if (!fgfa && fgfb) {
+ return false;
+ }
+ }
+
+ if (exactmatch && !rhs.exactmatch) {
+ return true;
+ }
+ if (!exactmatch && rhs.exactmatch) {
+ return false;
+ }
+
+ if (index != rhs.index) {
+ return index < rhs.index;
+ }
+
+ return false;
+ }
};
- static int filter_cmp(const void* a, const void* b);
CAtlList<filter_t> m_filters;
CAtlList<CFGFilter*> m_sortedfilters;
diff --git a/src/mpc-hc/PlayerSubresyncBar.cpp b/src/mpc-hc/PlayerSubresyncBar.cpp
index 11ec266cf..6a265b548 100644
--- a/src/mpc-hc/PlayerSubresyncBar.cpp
+++ b/src/mpc-hc/PlayerSubresyncBar.cpp
@@ -1,6 +1,6 @@
/*
* (C) 2003-2006 Gabest
- * (C) 2006-2016 see Authors.txt
+ * (C) 2006-2017 see Authors.txt
*
* This file is part of MPC-HC.
*
@@ -875,11 +875,6 @@ void CPlayerSubresyncBar::OnEndlabeleditList(NMHDR* pNMHDR, LRESULT* pResult)
}
}
-static int uintcomp(const void* i1, const void* i2)
-{
- return (*((UINT*)i2) - * ((UINT*)i1));
-}
-
void CPlayerSubresyncBar::OnRclickList(NMHDR* pNMHDR, LRESULT* pResult)
{
LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)pNMHDR;
@@ -1048,7 +1043,7 @@ void CPlayerSubresyncBar::OnRclickList(NMHDR* pNMHDR, LRESULT* pResult)
items.Add(m_list.GetNextSelectedItem(pos));
}
- qsort(items.GetData(), items.GetCount(), sizeof(UINT), uintcomp);
+ std::sort(items.GetData(), items.GetData() + items.GetCount(), std::greater<>());
for (INT_PTR i = 0, l = items.GetCount(); i < l; i++) {
iItem = items[i];
@@ -1077,7 +1072,7 @@ void CPlayerSubresyncBar::OnRclickList(NMHDR* pNMHDR, LRESULT* pResult)
items.Add(m_list.GetNextSelectedItem(pos));
}
- qsort(items.GetData(), items.GetCount(), sizeof(UINT), uintcomp);
+ std::sort(items.GetData(), items.GetData() + items.GetCount(), std::greater<>());
for (INT_PTR i = 0, l = items.GetCount(); i < l; i++) {
iItem = items[i];
diff --git a/src/mpc-hc/Playlist.cpp b/src/mpc-hc/Playlist.cpp
index d15453ed1..5396a5ebf 100644
--- a/src/mpc-hc/Playlist.cpp
+++ b/src/mpc-hc/Playlist.cpp
@@ -1,6 +1,6 @@
/*
* (C) 2003-2006 Gabest
- * (C) 2006-2015 see Authors.txt
+ * (C) 2006-2015, 2017 see Authors.txt
*
* This file is part of MPC-HC.
*
@@ -276,24 +276,20 @@ bool CPlaylist::RemoveAt(POSITION pos)
struct plsort_t {
UINT n;
POSITION pos;
-};
-static int compare(const void* arg1, const void* arg2)
-{
- UINT a1 = ((plsort_t*)arg1)->n;
- UINT a2 = ((plsort_t*)arg2)->n;
- return a1 > a2 ? 1 : a1 < a2 ? -1 : 0;
-}
+ bool operator <(const plsort_t& rhs) const {
+ return n < rhs.n;
+ }
+};
struct plsort2_t {
LPCTSTR str;
POSITION pos;
-};
-int compare2(const void* arg1, const void* arg2)
-{
- return StrCmpLogicalW(((plsort2_t*)arg1)->str, ((plsort2_t*)arg2)->str);
-}
+ bool operator <(const plsort2_t& rhs) const {
+ return StrCmpLogicalW(str, rhs.str) < 0;
+ }
+};
void CPlaylist::SortById()
{
@@ -303,7 +299,7 @@ void CPlaylist::SortById()
for (int i = 0; pos; i++, GetNext(pos)) {
a[i].n = GetAt(pos).m_id, a[i].pos = pos;
}
- qsort(a.GetData(), a.GetCount(), sizeof(plsort_t), compare);
+ std::sort(a.GetData(), a.GetData() + a.GetCount());
for (size_t i = 0; i < a.GetCount(); i++) {
MoveToTail(a[i].pos);
}
@@ -319,7 +315,7 @@ void CPlaylist::SortByName()
a[i].str = (LPCTSTR)fn + std::max(fn.ReverseFind('/'), fn.ReverseFind('\\')) + 1;
a[i].pos = pos;
}
- qsort(a.GetData(), a.GetCount(), sizeof(plsort2_t), compare2);
+ std::sort(a.GetData(), a.GetData() + a.GetCount());
for (size_t i = 0; i < a.GetCount(); i++) {
MoveToTail(a[i].pos);
}
@@ -333,7 +329,7 @@ void CPlaylist::SortByPath()
for (int i = 0; pos; i++, GetNext(pos)) {
a[i].str = GetAt(pos).m_fns.GetHead(), a[i].pos = pos;
}
- qsort(a.GetData(), a.GetCount(), sizeof(plsort2_t), compare2);
+ std::sort(a.GetData(), a.GetData() + a.GetCount());
for (size_t i = 0; i < a.GetCount(); i++) {
MoveToTail(a[i].pos);
}
@@ -348,7 +344,7 @@ void CPlaylist::Randomize()
for (int i = 0; pos; i++, GetNext(pos)) {
a[i].n = rand(), a[i].pos = pos;
}
- qsort(a.GetData(), a.GetCount(), sizeof(plsort_t), compare);
+ std::sort(a.GetData(), a.GetData() + a.GetCount());
for (size_t i = 0; i < a.GetCount(); i++) {
MoveToTail(a[i].pos);
}
@@ -432,7 +428,7 @@ void CPlaylist::SetShuffle(bool bEnable)
positions[i].n = rand();
positions[i].pos = pos;
}
- qsort(positions.GetData(), m_nShuffledListSize, sizeof(plsort_t), compare);
+ std::sort(positions.GetData(), positions.GetData() + m_nShuffledListSize);
positions[m_nShuffledListSize].pos = nullptr; // Termination
m_posHeadShuffle = positions[0].pos;