mirror of
https://github.com/reactos/reactos.git
synced 2025-06-26 20:49:50 +00:00
[RTL]
- Fix RtlFindSetBits to search for bits before the HintIndex as well - Remove a wrong (and commented out) ASSERT - Fix MSVC warnings svn path=/trunk/; revision=52536
This commit is contained in:
parent
f3a297daba
commit
c19f9ab75c
1 changed files with 24 additions and 15 deletions
|
@ -152,11 +152,11 @@ RtlFindMostSignificantBit(ULONGLONG Value)
|
||||||
|
|
||||||
if (BitScanReverse(&Position, Value >> 32))
|
if (BitScanReverse(&Position, Value >> 32))
|
||||||
{
|
{
|
||||||
return Position + 32;
|
return (CCHAR)(Position + 32);
|
||||||
}
|
}
|
||||||
else if (BitScanReverse(&Position, (ULONG)Value))
|
else if (BitScanReverse(&Position, (ULONG)Value))
|
||||||
{
|
{
|
||||||
return Position;
|
return (CCHAR)Position;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -170,11 +170,11 @@ RtlFindLeastSignificantBit(ULONGLONG Value)
|
||||||
|
|
||||||
if (BitScanForward(&Position, (ULONG)Value))
|
if (BitScanForward(&Position, (ULONG)Value))
|
||||||
{
|
{
|
||||||
return Position;
|
return (CCHAR)Position;
|
||||||
}
|
}
|
||||||
else if (BitScanForward(&Position, Value >> 32))
|
else if (BitScanForward(&Position, Value >> 32))
|
||||||
{
|
{
|
||||||
return Position + 32;
|
return (CCHAR)(Position + 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -187,9 +187,6 @@ RtlInitializeBitMap(
|
||||||
IN PULONG BitMapBuffer,
|
IN PULONG BitMapBuffer,
|
||||||
IN ULONG SizeOfBitMap)
|
IN ULONG SizeOfBitMap)
|
||||||
{
|
{
|
||||||
// FIXME: some bugger here!
|
|
||||||
//ASSERT(SizeOfBitMap > 0);
|
|
||||||
|
|
||||||
/* Setup the bitmap header */
|
/* Setup the bitmap header */
|
||||||
BitMapHeader->SizeOfBitMap = SizeOfBitMap;
|
BitMapHeader->SizeOfBitMap = SizeOfBitMap;
|
||||||
BitMapHeader->Buffer = BitMapBuffer;
|
BitMapHeader->Buffer = BitMapBuffer;
|
||||||
|
@ -212,7 +209,7 @@ RtlSetAllBits(
|
||||||
IN OUT PRTL_BITMAP BitMapHeader)
|
IN OUT PRTL_BITMAP BitMapHeader)
|
||||||
{
|
{
|
||||||
ULONG LengthInUlongs;
|
ULONG LengthInUlongs;
|
||||||
|
|
||||||
LengthInUlongs = (BitMapHeader->SizeOfBitMap + 31) >> 5;
|
LengthInUlongs = (BitMapHeader->SizeOfBitMap + 31) >> 5;
|
||||||
RtlFillMemoryUlong(BitMapHeader->Buffer, LengthInUlongs << 2, ~0);
|
RtlFillMemoryUlong(BitMapHeader->Buffer, LengthInUlongs << 2, ~0);
|
||||||
}
|
}
|
||||||
|
@ -481,7 +478,7 @@ RtlFindSetBits(
|
||||||
IN ULONG NumberToFind,
|
IN ULONG NumberToFind,
|
||||||
IN ULONG HintIndex)
|
IN ULONG HintIndex)
|
||||||
{
|
{
|
||||||
ULONG CurrentBit, CurrentLength;
|
ULONG CurrentBit, Margin, CurrentLength;
|
||||||
|
|
||||||
/* Check for valid parameters */
|
/* Check for valid parameters */
|
||||||
if (!BitMapHeader || NumberToFind > BitMapHeader->SizeOfBitMap)
|
if (!BitMapHeader || NumberToFind > BitMapHeader->SizeOfBitMap)
|
||||||
|
@ -495,12 +492,15 @@ RtlFindSetBits(
|
||||||
return HintIndex;
|
return HintIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* First margin is end of bitmap */
|
||||||
|
Margin = BitMapHeader->SizeOfBitMap;
|
||||||
|
|
||||||
|
retry:
|
||||||
/* Start with hint index, length is 0 */
|
/* Start with hint index, length is 0 */
|
||||||
CurrentBit = HintIndex;
|
CurrentBit = HintIndex;
|
||||||
CurrentLength = 0;
|
|
||||||
|
|
||||||
/* Loop until something is found or the end is reached */
|
/* Loop until something is found or the end is reached */
|
||||||
while (CurrentBit + NumberToFind <= BitMapHeader->SizeOfBitMap)
|
while (CurrentBit + NumberToFind <= Margin)
|
||||||
{
|
{
|
||||||
/* Search for the next set run, by skipping a clear run */
|
/* Search for the next set run, by skipping a clear run */
|
||||||
CurrentBit += RtlpGetLengthOfRunClear(BitMapHeader,
|
CurrentBit += RtlpGetLengthOfRunClear(BitMapHeader,
|
||||||
|
@ -522,6 +522,15 @@ RtlFindSetBits(
|
||||||
CurrentBit += CurrentLength;
|
CurrentBit += CurrentLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Did we start at a hint? */
|
||||||
|
if (HintIndex)
|
||||||
|
{
|
||||||
|
/* Retry at the start */
|
||||||
|
Margin = min(HintIndex + NumberToFind, BitMapHeader->SizeOfBitMap);
|
||||||
|
HintIndex = 0;
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
|
|
||||||
/* Nothing found */
|
/* Nothing found */
|
||||||
return MAXULONG;
|
return MAXULONG;
|
||||||
}
|
}
|
||||||
|
@ -641,7 +650,7 @@ RtlFindClearRuns(
|
||||||
for (Run = 0; Run < SizeOfRunArray; Run++)
|
for (Run = 0; Run < SizeOfRunArray; Run++)
|
||||||
{
|
{
|
||||||
/* Look for a run */
|
/* Look for a run */
|
||||||
NumberOfBits = RtlFindNextForwardRunClear(BitMapHeader,
|
NumberOfBits = RtlFindNextForwardRunClear(BitMapHeader,
|
||||||
FromIndex,
|
FromIndex,
|
||||||
&StartingIndex);
|
&StartingIndex);
|
||||||
|
|
||||||
|
@ -672,7 +681,7 @@ RtlFindClearRuns(
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
/* Look for a run */
|
/* Look for a run */
|
||||||
NumberOfBits = RtlFindNextForwardRunClear(BitMapHeader,
|
NumberOfBits = RtlFindNextForwardRunClear(BitMapHeader,
|
||||||
FromIndex,
|
FromIndex,
|
||||||
&StartingIndex);
|
&StartingIndex);
|
||||||
|
|
||||||
|
@ -716,7 +725,7 @@ RtlFindLongestRunClear(
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
/* Look for a run */
|
/* Look for a run */
|
||||||
NumberOfBits = RtlFindNextForwardRunClear(BitMapHeader,
|
NumberOfBits = RtlFindNextForwardRunClear(BitMapHeader,
|
||||||
FromIndex,
|
FromIndex,
|
||||||
&Index);
|
&Index);
|
||||||
|
|
||||||
|
@ -749,7 +758,7 @@ RtlFindLongestRunSet(
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
/* Look for a run */
|
/* Look for a run */
|
||||||
NumberOfBits = RtlFindNextForwardRunSet(BitMapHeader,
|
NumberOfBits = RtlFindNextForwardRunSet(BitMapHeader,
|
||||||
FromIndex,
|
FromIndex,
|
||||||
&Index);
|
&Index);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue