Module: wine Branch: master Commit: 500ec80e9fe574044bacc410cd96ea9009c3fe5d URL: https://gitlab.winehq.org/wine/wine/-/commit/500ec80e9fe574044bacc410cd96ea9...
Author: Alexandre Julliard julliard@winehq.org Date: Sat Apr 22 17:32:25 2023 +0200
ntdll: Reimplement RtlClearBits() to clear 32 bits at a time.
---
dlls/ntdll/rtlbitmap.c | 61 +++++++++----------------------------------------- 1 file changed, 11 insertions(+), 50 deletions(-)
diff --git a/dlls/ntdll/rtlbitmap.c b/dlls/ntdll/rtlbitmap.c index 4ca3df3351c..3c3f2182a72 100644 --- a/dlls/ntdll/rtlbitmap.c +++ b/dlls/ntdll/rtlbitmap.c @@ -142,63 +142,24 @@ void WINAPI RtlSetBits( RTL_BITMAP *bitmap, ULONG start, ULONG count )
/************************************************************************* * RtlClearBits [NTDLL.@] - * - * Clear bits in a bitmap. - * - * PARAMS - * lpBits [I] Bitmap pointer - * ulStart [I] First bit to set - * ulCount [I] Number of consecutive bits to clear - * - * RETURNS - * Nothing. */ -VOID WINAPI RtlClearBits(PRTL_BITMAP lpBits, ULONG ulStart, ULONG ulCount) +void WINAPI RtlClearBits( RTL_BITMAP *bitmap, ULONG start, ULONG count) { - LPBYTE lpOut; - - TRACE("(%p,%lu,%lu)\n", lpBits, ulStart, ulCount); + ULONG end = start + count; + ULONG pos = start / 32; + ULONG end_pos = end / 32;
- if (!lpBits || !ulCount || - ulStart >= lpBits->SizeOfBitMap || - ulCount > lpBits->SizeOfBitMap - ulStart) - return; + TRACE( "(%p,%lu,%lu)\n", bitmap, start, count );
- /* FIXME: It might be more efficient/cleaner to manipulate four bytes - * at a time. But beware of the pointer arithmetics... - */ - lpOut = ((BYTE*)lpBits->Buffer) + (ulStart >> 3u); + if (!count || start >= bitmap->SizeOfBitMap || count > bitmap->SizeOfBitMap - start) return;
- /* Clear bits in first byte, if ulStart isn't a byte boundary */ - if (ulStart & 7) - { - if (ulCount > 7) - { - /* Clear from start bit to the end of the byte */ - *lpOut++ &= ~(0xff << (ulStart & 7)); - ulCount -= (8 - (ulStart & 7)); - } - else + if (end_pos > pos) { - /* Clear from the start bit, possibly into the next byte also */ - USHORT initialWord = ~(NTDLL_maskBits[ulCount] << (ulStart & 7)); - - *lpOut &= (initialWord & 0xff); - if ((initialWord >> 8) != 0xff) lpOut[1] &= (initialWord >> 8); - return; + bitmap->Buffer[pos++] &= ~maskbits( start ); + while (pos < end_pos) bitmap->Buffer[pos++] = 0; + if (end & 31) bitmap->Buffer[pos] &= maskbits( end ); } - } - - /* Clear bits (in blocks of 8) on whole byte boundaries */ - if (ulCount >> 3) - { - memset(lpOut, 0, ulCount >> 3); - lpOut = lpOut + (ulCount >> 3); - } - - /* Clear remaining bits, if any */ - if (ulCount & 0x7) - *lpOut &= ~NTDLL_maskBits[ulCount & 0x7]; + else bitmap->Buffer[pos] &= ~maskbits( start ) | maskbits( end ); }
/*************************************************************************