Skip to content

Commit c238544

Browse files
Opt, 消除项目中的警告
1 parent 1ac92c9 commit c238544

File tree

8 files changed

+43
-19
lines changed

8 files changed

+43
-19
lines changed

include/YY/Base/Containers/Array.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ namespace YY
408408
auto _uSize = _pOldSharedData->GetSize();
409409
SharedData* _pNewSharedData;
410410

411-
if constexpr (std::is_trivially_copyable<_Type>::value)
411+
if YY_CPP17_IF_CONSTEXPR (std::is_trivially_copyable<_Type>::value)
412412
{
413413
_pNewSharedData = (SharedData*)YY::Base::Memory::ReAlloc(_pOldSharedData, sizeof(SharedData) + sizeof(_Type) * _uNewCapacity);
414414
if (!_pNewSharedData)
@@ -833,7 +833,7 @@ namespace YY
833833
return E_INVALIDARG;
834834
}
835835

836-
if constexpr (std::is_trivially_copyable<_Type>::value)
836+
if YY_CPP17_IF_CONSTEXPR (std::is_trivially_copyable<_Type>::value)
837837
{
838838
auto _pData = (_Type*)ReAlloc(Large.pData, _uNewCapacity * sizeof(_Type));
839839
if (!_pData)

include/YY/Base/Containers/ConstructorPolicy.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#pragma once
1+
#pragma once
22
#include <string.h>
3+
#include <YY/Base/YY.h>
34

45
namespace YY
56
{
@@ -12,7 +13,7 @@ namespace YY
1213
{
1314
static void Constructor(_Type* _pFirst, _Type* _pLast)
1415
{
15-
if constexpr (std::is_trivially_constructible<_Type>::value)
16+
if YY_CPP17_IF_CONSTEXPR (std::is_trivially_constructible<_Type>::value)
1617
{
1718
memset(_pFirst, 0, (_pLast - _pFirst) * sizeof(*_pFirst));
1819
}
@@ -27,7 +28,7 @@ namespace YY
2728

2829
static void MoveConstructor(_Type* _pDst, _Type* _pFirst, _Type* _pLast)
2930
{
30-
if constexpr (std::is_trivially_constructible<_Type>::value)
31+
if YY_CPP17_IF_CONSTEXPR (std::is_trivially_constructible<_Type>::value)
3132
{
3233
memcpy(_pDst, _pFirst, (_pLast - _pFirst) * sizeof(*_pFirst));
3334
}
@@ -47,7 +48,7 @@ namespace YY
4748

4849
static void CopyConstructor(_Type* _pDst, const _Type* _pFirst, const _Type* _pLast)
4950
{
50-
if constexpr (std::is_trivially_constructible<_Type>::value)
51+
if YY_CPP17_IF_CONSTEXPR (std::is_trivially_constructible<_Type>::value)
5152
{
5253
memcpy(_pDst, _pFirst, (_pLast - _pFirst) * sizeof(*_pFirst));
5354
}
@@ -67,9 +68,9 @@ namespace YY
6768

6869
static void Destructor(_Type* _pFirst, _Type* _pLast)
6970
{
70-
if constexpr (std::is_trivially_destructible<_Type>::value)
71+
if YY_CPP17_IF_CONSTEXPR (std::is_trivially_destructible<_Type>::value)
7172
{
72-
// 如果是平坦的,那么什么也不做
73+
// 如果是平坦的,那么什么也不做
7374
return;
7475
}
7576
else
@@ -88,7 +89,7 @@ namespace YY
8889

8990
static void Copy(_Type* _pDst, const _Type* _pFirst, const _Type* _pLast)
9091
{
91-
if constexpr (std::is_trivially_copyable<_Type>::value)
92+
if YY_CPP17_IF_CONSTEXPR (std::is_trivially_copyable<_Type>::value)
9293
{
9394
memcpy(_pDst, _pFirst, (_pLast - _pFirst) * sizeof(*_pFirst));
9495
}
@@ -108,19 +109,19 @@ namespace YY
108109

109110
static void Move(_Type* _pDst, _Type* _pFirst, _Type* _pLast)
110111
{
111-
if constexpr (std::is_trivially_copyable<_Type>::value)
112+
if YY_CPP17_IF_CONSTEXPR (std::is_trivially_copyable<_Type>::value)
112113
{
113114
memmove(_pDst, _pFirst, (_pLast - _pFirst) * sizeof(*_pFirst));
114115
}
115116
else
116117
{
117118
if (_pDst == _pFirst)
118119
{
119-
// 完全一样,复制啥???
120+
// 完全一样,复制啥???
120121
}
121122
else if (_pFirst > _pDst && _pDst < _pLast)
122123
{
123-
// 区域层叠,我们进行颠倒移动。
124+
// 区域层叠,我们进行颠倒移动。
124125
auto _pDstLast = _pDst + (_pLast - _pFirst);
125126

126127
while (_pFirst != _pLast)

include/YY/Base/Threading/Coroutine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ namespace YY
178178
}
179179
catch (const YY::Base::OperationCanceledException& _Exception)
180180
{
181+
UNREFERENCED_PARAMETER(_Exception);
181182
return YY::Base::HRESULT_From_LSTATUS(ERROR_CANCELLED);
182183
}
183184
}

include/YY/Base/Utils/MathUtils.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ namespace YY
4141
uint32_t _Ret[4] = {};
4242

4343
uint64_t _uRemainder = _HighDividend >> 32;
44-
_Ret[3] = _uRemainder / _Divisor;
44+
_Ret[3] = uint32_t(_uRemainder / _Divisor);
4545
_uRemainder %= _Divisor;
4646

4747
_uRemainder = (_uRemainder << 32) | (_HighDividend & 0xFFFFFFFFull);
48-
_Ret[2] = _uRemainder / _Divisor;
48+
_Ret[2] = uint32_t(_uRemainder / _Divisor);
4949
_uRemainder %= _Divisor;
5050

5151
_uRemainder = (_uRemainder << 32) | (_LowDividend >> 32);
52-
_Ret[1] = _uRemainder / _Divisor;
52+
_Ret[1] = uint32_t(_uRemainder / _Divisor);
5353
_uRemainder %= _Divisor;
5454

5555
_uRemainder = (_uRemainder << 32) | (_LowDividend & 0xFFFFFFFFull);
56-
_Ret[0] = _uRemainder / _Divisor;
56+
_Ret[0] = uint32_t(_uRemainder / _Divisor);
5757
_uRemainder %= _Divisor;
5858

5959
*_Remainder = _uRemainder;

include/YY/Base/YY.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@
102102
return (_Type)_eLeft & (_Type)_eRight; \
103103
}
104104

105+
#if defined(_HAS_CXX17) && _HAS_CXX17
106+
// 支持if constexpr(condition) ...
107+
#define YY_CPP17_IF_CONSTEXPR constexpr
108+
#else
109+
// 不支持if constexpr(condition) ...,只能使用普通的if,无法在编译期进行分支判断了。
110+
#define YY_CPP17_IF_CONSTEXPR
111+
#endif // _HAS_CXX17
112+
105113
namespace YY
106114
{
107115
namespace Base

src/YY/Base/Sync/Sync.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include <YY/Base/Sync/Sync.h>
22
#include <YY/Base/Time/TickCount.h>
33

4+
#include <utility>
5+
46
#pragma comment(lib, "Synchronization.lib")
57

68
__YY_IGNORE_INCONSISTENT_ANNOTATION_FOR_FUNCTION()
@@ -47,7 +49,8 @@ namespace YY
4749
if (_uCurrent > _uExpireTick)
4850
return false;
4951

50-
if (!WaitOnAddress(_pAddress, &_Temp, sizeof(_Temp), (_uExpireTick - _uCurrent).GetTotalMilliseconds()))
52+
const auto _iTotalMilliseconds = (_uExpireTick - _uCurrent).GetTotalMilliseconds();
53+
if (!WaitOnAddress(_pAddress, &_Temp, sizeof(_Temp), _iTotalMilliseconds <= 0 ? 0ul : (DWORD)(std::min)(_iTotalMilliseconds, static_cast<int64_t>(UINT32_MAX))))
5154
return false;
5255
}
5356

src/YY/Base/Threading/TaskRunner.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ namespace YY
7474
}
7575
catch (const YY::Base::OperationCanceledException& _Exception)
7676
{
77+
UNREFERENCED_PARAMETER(_Exception);
7778
_hr = YY::Base::HRESULT_From_LSTATUS(ERROR_CANCELLED);
7879
}
7980

@@ -101,6 +102,7 @@ namespace YY
101102
}
102103
catch (const YY::Base::OperationCanceledException& _Exception)
103104
{
105+
UNREFERENCED_PARAMETER(_Exception);
104106
_hr = YY::Base::HRESULT_From_LSTATUS(ERROR_CANCELLED);
105107
}
106108

@@ -429,6 +431,7 @@ namespace YY
429431
}
430432
catch (const YY::Base::OperationCanceledException& _Exception)
431433
{
434+
UNREFERENCED_PARAMETER(_Exception);
432435
return YY::Base::HRESULT_From_LSTATUS(ERROR_CANCELLED);
433436
}
434437
}
@@ -658,6 +661,7 @@ namespace YY
658661
}
659662
catch (const YY::Base::OperationCanceledException& _Exception)
660663
{
664+
UNREFERENCED_PARAMETER(_Exception);
661665
_hr = HRESULT_From_LSTATUS(ERROR_CANCELLED);
662666
}
663667

src/YY/Base/Threading/TaskRunnerDispatchImpl.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ namespace YY
104104
DispatchTask(std::move(_pTimer));
105105
},
106106
_pTimer.Get(),
107-
_iDueTime,
107+
(DWORD)(std::min)(_iDueTime, static_cast<int64_t>(UINT32_MAX)),
108108
0,
109109
WT_EXECUTEINTIMERTHREAD | WT_EXECUTEONLYONCE);
110110

@@ -133,6 +133,13 @@ namespace YY
133133
}
134134
}
135135
}
136+
const auto _iTotalMilliseconds = (_pWait->uTimeOut - TickCount::GetNow()).GetTotalMilliseconds();
137+
if (_iTotalMilliseconds <= 0)
138+
{
139+
_pWait->uWaitResult = WaitForSingleObject(_pWait->hHandle, 0);
140+
DispatchTask(std::move(_pWait));
141+
return S_OK;
142+
}
136143

137144
_pWait.Get()->AddWeakRef();
138145
// 我们使用 RegisterWaitForSingleObject 这是因为它允许我们在线程池线程中执行回调,没有额外的上下文切换开销。
@@ -158,7 +165,7 @@ namespace YY
158165
DispatchTask(std::move(_pWait));
159166
},
160167
_pWait.Get(),
161-
(_pWait->uTimeOut - TickCount::GetNow()).GetTotalMilliseconds(),
168+
(DWORD)(std::min)(_iTotalMilliseconds, static_cast<int64_t>(UINT32_MAX)),
162169
WT_EXECUTEINWAITTHREAD | WT_EXECUTEONLYONCE);
163170

164171
if (!_bRet)

0 commit comments

Comments
 (0)