mirror of
https://github.com/reactos/reactos.git
synced 2024-07-31 16:48:14 +00:00
- Fix implementation of RtlFindSetBits to be able to return bits that are at lower location than the supplied hint.
svn path=/trunk/; revision=11053
This commit is contained in:
parent
91fea9194d
commit
3823d945f5
|
@ -16,7 +16,7 @@
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
/* $Id: bitmap.c,v 1.3 2004/09/25 19:39:57 navaraf Exp $
|
/* $Id: bitmap.c,v 1.4 2004/09/25 20:49:57 navaraf Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -600,6 +600,9 @@ RtlFindSetBits(PRTL_BITMAP BitMapHeader,
|
||||||
ULONG Count;
|
ULONG Count;
|
||||||
PULONG Ptr;
|
PULONG Ptr;
|
||||||
ULONG Mask;
|
ULONG Mask;
|
||||||
|
ULONG Loop;
|
||||||
|
ULONG End;
|
||||||
|
ULONG OriginalHint = HintIndex;
|
||||||
|
|
||||||
Size = BitMapHeader->SizeOfBitMap;
|
Size = BitMapHeader->SizeOfBitMap;
|
||||||
if (NumberToFind > Size || NumberToFind == 0)
|
if (NumberToFind > Size || NumberToFind == 0)
|
||||||
|
@ -608,40 +611,60 @@ RtlFindSetBits(PRTL_BITMAP BitMapHeader,
|
||||||
if (HintIndex >= Size)
|
if (HintIndex >= Size)
|
||||||
HintIndex = 0;
|
HintIndex = 0;
|
||||||
|
|
||||||
|
/* Initialize the values to the hint location. */
|
||||||
Index = HintIndex;
|
Index = HintIndex;
|
||||||
Ptr = (PULONG)BitMapHeader->Buffer + (Index / 32);
|
Ptr = BitMapHeader->Buffer + (Index / 32);
|
||||||
Mask = 1 << (Index & 0x1F);
|
Mask = 1 << (Index & 0x1F);
|
||||||
|
End = Size;
|
||||||
|
|
||||||
while (HintIndex < Size)
|
/* The outer loop does the magic of first searching from the
|
||||||
|
* hint to the bitmap end and then going again from beginning
|
||||||
|
* of the bitmap to the hint location.
|
||||||
|
*/
|
||||||
|
for (Loop = 0; Loop < 2; Loop++)
|
||||||
{
|
{
|
||||||
/* Count set bits */
|
while (HintIndex < End)
|
||||||
for (Count = 0; Index < Size && *Ptr & Mask; Index++)
|
|
||||||
{
|
{
|
||||||
if (++Count >= NumberToFind)
|
/* Count set bits */
|
||||||
return HintIndex;
|
for (Count = 0; Index < End && *Ptr & Mask; Index++)
|
||||||
|
|
||||||
Mask <<= 1;
|
|
||||||
|
|
||||||
if (Mask == 0)
|
|
||||||
{
|
{
|
||||||
Mask = 1;
|
if (++Count >= NumberToFind)
|
||||||
Ptr++;
|
return HintIndex;
|
||||||
|
|
||||||
|
Mask <<= 1;
|
||||||
|
|
||||||
|
if (Mask == 0)
|
||||||
|
{
|
||||||
|
Mask = 1;
|
||||||
|
Ptr++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Skip clear bits */
|
||||||
|
for (; Index < End && ~*Ptr & Mask; Index++)
|
||||||
|
{
|
||||||
|
Mask <<= 1;
|
||||||
|
|
||||||
|
if (Mask == 0)
|
||||||
|
{
|
||||||
|
Mask = 1;
|
||||||
|
Ptr++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HintIndex = Index;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip clear bits */
|
/* Optimalization */
|
||||||
for (; Index < Size && ~*Ptr & Mask; Index++)
|
if (OriginalHint == 0)
|
||||||
{
|
break;
|
||||||
Mask <<= 1;
|
|
||||||
|
|
||||||
if (Mask == 0)
|
/* Initialize the values for the beginning -> hint loop. */
|
||||||
{
|
HintIndex = Index = 0;
|
||||||
Mask = 1;
|
End = OriginalHint + NumberToFind - 1;
|
||||||
Ptr++;
|
End = End > Size ? Size : End;
|
||||||
}
|
Ptr = BitMapHeader->Buffer;
|
||||||
}
|
Mask = 1;
|
||||||
|
|
||||||
HintIndex = Index;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (ULONG)-1;
|
return (ULONG)-1;
|
||||||
|
|
Loading…
Reference in a new issue