mirror of
https://github.com/Chuyu-Team/YY-Thunks.git
synced 2026-10-28 22:08:22 +08:00
将EnumCalendarInfoExExDataInfo、EnumDateFormatsExExDataInfo合并到ThreadContext,减少内存占用。
This commit is contained in:
@@ -113,7 +113,7 @@ YY-Thunks(鸭船),存在的目的就是抹平不同系统的差异,编
|
||||
| [SetThreadErrorMode](https://docs.microsoft.com/en-us/windows/desktop/api/errhandlingapi/nf-errhandlingapi-setthreaderrormode) | 不存在时,调用SetErrorMode。
|
||||
| [GetThreadErrorMode](https://docs.microsoft.com/en-us/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getthreaderrormode) | 不存在时,调用GetErrorMode。
|
||||
| [GetErrorMode](https://docs.microsoft.com/en-us/windows/desktop/api/errhandlingapi/nf-errhandlingapi-geterrormode) | 不存在时,调用NtQueryInformationProcess。
|
||||
| [InitializeSRWLock](https://docs.microsoft.com/zh-cn/windows/desktop/api/synchapi/nf-synchapi-initializesrwlock) | 不存在时,初始化为 0。
|
||||
| [InitializeSRWLock](https://docs.microsoft.com/zh-cn/windows/desktop/api/synchapi/nf-synchapi-initializesrwlock) | 初始化为 RTL_SRWLOCK_INIT。
|
||||
| [AcquireSRWLockExclusive](https://docs.microsoft.com/zh-cn/windows/desktop/api/synchapi/nf-synchapi-acquiresrwlockexclusive) | 不存在时,调用InterlockedBitTestAndSet(64)。
|
||||
| [TryAcquireSRWLockExclusive](https://msdn.microsoft.com/en-us/library/Dd405523.aspx) | 不存在时,调用InterlockedBitTestAndSet(64)。
|
||||
| [ReleaseSRWLockExclusive](https://msdn.microsoft.com/en-us/library/ms685076.aspx) | 不存在时,调用InterlockedCompareExchange。
|
||||
@@ -236,3 +236,8 @@ YY-Thunks(鸭船),存在的目的就是抹平不同系统的差异,编
|
||||
* 添加ReleaseSRWLockShared
|
||||
* 添加TryAcquireSRWLockExclusive
|
||||
* 添加TryAcquireSRWLockShared
|
||||
|
||||
|
||||
### 1.0.1.8 - 优化实现(2019-06-10 13:00)
|
||||
* 优化代码结构,减少不必要的全局对象引入。
|
||||
* 内部函数采用__fastcall约定,减少栈操作。
|
||||
|
||||
+61
-26
@@ -112,6 +112,7 @@
|
||||
#include <WinSock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <psapi.h>
|
||||
#include <winnls.h>
|
||||
#include "YY_Thunks.h"
|
||||
|
||||
#if (YY_Thunks_Support_Version < NTDDI_WS03SP1)
|
||||
@@ -150,6 +151,24 @@ namespace YY
|
||||
SetLastError(lStatus);
|
||||
return lStatus;
|
||||
}
|
||||
|
||||
EXTERN_C typedef struct _ThreadContext
|
||||
{
|
||||
union
|
||||
{
|
||||
CALINFO_ENUMPROCEXEX pCalInfoEnumProcExEx;
|
||||
DATEFMT_ENUMPROCEXEX lpDateFmtEnumProcExEx;
|
||||
};
|
||||
|
||||
LPARAM lParam;
|
||||
} ThreadContext;
|
||||
|
||||
static ThreadContext* __fastcall BaseGetThreadContext()
|
||||
{
|
||||
static thread_local ThreadContext ThreadContext = {};
|
||||
|
||||
return &ThreadContext;
|
||||
}
|
||||
}
|
||||
|
||||
#if (YY_Thunks_Support_Version < NTDDI_WS03SP1)
|
||||
@@ -2035,6 +2054,7 @@ _LCRT_DEFINE_IAT_SYMBOL(LCIDToLocaleName, _16);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if (YY_Thunks_Support_Version < NTDDI_WIN6)
|
||||
//Windows Vista, Windows Server 2008
|
||||
|
||||
@@ -2103,6 +2123,7 @@ _LCRT_DEFINE_IAT_SYMBOL(GetDateFormatEx, _28);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if (YY_Thunks_Support_Version < NTDDI_WIN6)
|
||||
//Windows Vista, Windows Server 2008
|
||||
|
||||
@@ -2138,6 +2159,7 @@ _LCRT_DEFINE_IAT_SYMBOL(GetTimeFormatEx, _24);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if (YY_Thunks_Support_Version < NTDDI_WIN6)
|
||||
//Windows Vista, Windows Server 2008
|
||||
|
||||
@@ -2174,6 +2196,7 @@ _LCRT_DEFINE_IAT_SYMBOL(GetNumberFormatEx, _24);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if (YY_Thunks_Support_Version < NTDDI_WIN6)
|
||||
//Windows Vista, Windows Server 2008
|
||||
|
||||
@@ -2210,6 +2233,7 @@ _LCRT_DEFINE_IAT_SYMBOL(GetCurrencyFormatEx, _24);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if (YY_Thunks_Support_Version < NTDDI_WIN6)
|
||||
//Windows Vista, Windows Server 2008
|
||||
|
||||
@@ -2234,6 +2258,7 @@ _LCRT_DEFINE_IAT_SYMBOL(GetUserDefaultLocaleName, _8);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if (YY_Thunks_Support_Version < NTDDI_WIN6)
|
||||
//Windows Vista, Windows Server 2008
|
||||
|
||||
@@ -2258,17 +2283,9 @@ _LCRT_DEFINE_IAT_SYMBOL(GetSystemDefaultLocaleName, _8);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if (YY_Thunks_Support_Version < NTDDI_WIN6)
|
||||
//Windows Vista, Windows Server 2008
|
||||
#include <winnls.h>
|
||||
|
||||
struct EnumCalendarInfoExExDataInfo
|
||||
{
|
||||
CALINFO_ENUMPROCEXEX pCalInfoEnumProcExEx;
|
||||
LPARAM lParam;
|
||||
};
|
||||
|
||||
static thread_local EnumCalendarInfoExExDataInfo __EnumCalendarInfoExExDataInfo;
|
||||
|
||||
EXTERN_C
|
||||
BOOL
|
||||
@@ -2302,17 +2319,29 @@ EnumCalendarInfoExEx(
|
||||
}
|
||||
|
||||
//保存上下文
|
||||
__EnumCalendarInfoExExDataInfo.pCalInfoEnumProcExEx = pCalInfoEnumProcExEx;
|
||||
__EnumCalendarInfoExExDataInfo.lParam = lParam;
|
||||
auto pContext = internal::BaseGetThreadContext();
|
||||
|
||||
return EnumCalendarInfoExW(
|
||||
auto pCalInfoEnumProcExExTmp = pContext->pCalInfoEnumProcExEx;
|
||||
pContext->pCalInfoEnumProcExEx = pCalInfoEnumProcExEx;
|
||||
|
||||
auto lParamTmp = pContext->lParam;
|
||||
pContext->lParam = lParam;
|
||||
|
||||
auto bSuccess = EnumCalendarInfoExW(
|
||||
[](LPWSTR lpCalendarInfoString, CALID Calendar)->BOOL
|
||||
{
|
||||
return __EnumCalendarInfoExExDataInfo.pCalInfoEnumProcExEx(lpCalendarInfoString, Calendar, nullptr, __EnumCalendarInfoExExDataInfo.lParam);
|
||||
auto pContext = internal::BaseGetThreadContext();
|
||||
return pContext->pCalInfoEnumProcExEx(lpCalendarInfoString, Calendar, nullptr, pContext->lParam);
|
||||
},
|
||||
Locale,
|
||||
Calendar,
|
||||
CalType);
|
||||
|
||||
//恢复上下文
|
||||
pContext->pCalInfoEnumProcExEx = pCalInfoEnumProcExExTmp;
|
||||
pContext->lParam = lParamTmp;
|
||||
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
_LCRT_DEFINE_IAT_SYMBOL(EnumCalendarInfoExEx, _24);
|
||||
@@ -2322,15 +2351,6 @@ _LCRT_DEFINE_IAT_SYMBOL(EnumCalendarInfoExEx, _24);
|
||||
|
||||
#if (YY_Thunks_Support_Version < NTDDI_WIN6)
|
||||
//Windows Vista, Windows Server 2008
|
||||
#include <winnls.h>
|
||||
|
||||
struct EnumDateFormatsExExDataInfo
|
||||
{
|
||||
DATEFMT_ENUMPROCEXEX pCalInfoEnumProcExEx;
|
||||
LPARAM lParam;
|
||||
};
|
||||
|
||||
static thread_local EnumDateFormatsExExDataInfo __EnumDateFormatsExExDataInfo;
|
||||
|
||||
EXTERN_C
|
||||
BOOL
|
||||
@@ -2362,22 +2382,36 @@ EnumDateFormatsExEx(
|
||||
}
|
||||
|
||||
//保存上下文
|
||||
__EnumDateFormatsExExDataInfo.pCalInfoEnumProcExEx = lpDateFmtEnumProcExEx;
|
||||
__EnumDateFormatsExExDataInfo.lParam = lParam;
|
||||
auto pContext = internal::BaseGetThreadContext();
|
||||
|
||||
return EnumDateFormatsExW(
|
||||
auto lpDateFmtEnumProcExExTmp = pContext->lpDateFmtEnumProcExEx;
|
||||
pContext->lpDateFmtEnumProcExEx = lpDateFmtEnumProcExEx;
|
||||
|
||||
auto lParamTmp = pContext->lParam;
|
||||
pContext->lParam = lParam;
|
||||
|
||||
auto pSuccess = EnumDateFormatsExW(
|
||||
[](LPWSTR lpDateFormatString, CALID CalendarID)->BOOL
|
||||
{
|
||||
return __EnumDateFormatsExExDataInfo.pCalInfoEnumProcExEx(lpDateFormatString, CalendarID, __EnumCalendarInfoExExDataInfo.lParam);
|
||||
auto pContext = internal::BaseGetThreadContext();
|
||||
return pContext->lpDateFmtEnumProcExEx(lpDateFormatString, CalendarID, pContext->lParam);
|
||||
},
|
||||
Locale,
|
||||
dwFlags);
|
||||
|
||||
|
||||
//恢复上下文
|
||||
pContext->lpDateFmtEnumProcExEx = lpDateFmtEnumProcExExTmp;
|
||||
pContext->lParam = lParamTmp;
|
||||
|
||||
return pSuccess;
|
||||
}
|
||||
|
||||
_LCRT_DEFINE_IAT_SYMBOL(EnumDateFormatsExEx, _16);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if (YY_Thunks_Support_Version < NTDDI_WIN6)
|
||||
//Windows Vista, Windows Server 2008
|
||||
|
||||
@@ -2526,6 +2560,7 @@ _LCRT_DEFINE_IAT_SYMBOL(GetFileInformationByHandleEx, _16);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if (YY_Thunks_Support_Version < NTDDI_WIN6)
|
||||
//Windows Vista, Windows Server 2008
|
||||
|
||||
|
||||
Reference in New Issue
Block a user