Sort the key indexes in CM.

svn path=/trunk/; revision=24478
This commit is contained in:
Filip Navara 2006-10-09 23:43:06 +00:00
parent ca6e7110f5
commit 7bbb81a0d4
2 changed files with 29 additions and 9 deletions

View file

@ -216,6 +216,7 @@ RegCreateKey(FRLDRHKEY ParentKey,
int subkeyLength; int subkeyLength;
int stringLength; int stringLength;
ULONG NameSize; ULONG NameSize;
int CmpResult;
DbgPrint((DPRINT_REGISTRY, "KeyName '%S'\n", KeyName)); DbgPrint((DPRINT_REGISTRY, "KeyName '%S'\n", KeyName));
@ -261,6 +262,7 @@ RegCreateKey(FRLDRHKEY ParentKey,
NameSize = (subkeyLength + 1) * sizeof(WCHAR); NameSize = (subkeyLength + 1) * sizeof(WCHAR);
Ptr = CurrentKey->SubKeyList.Flink; Ptr = CurrentKey->SubKeyList.Flink;
CmpResult = 1;
while (Ptr != &CurrentKey->SubKeyList) while (Ptr != &CurrentKey->SubKeyList)
{ {
DbgPrint((DPRINT_REGISTRY, "Ptr 0x%x\n", Ptr)); DbgPrint((DPRINT_REGISTRY, "Ptr 0x%x\n", Ptr));
@ -270,14 +272,16 @@ RegCreateKey(FRLDRHKEY ParentKey,
KeyList); KeyList);
DbgPrint((DPRINT_REGISTRY, "SearchKey 0x%x\n", SearchKey)); DbgPrint((DPRINT_REGISTRY, "SearchKey 0x%x\n", SearchKey));
DbgPrint((DPRINT_REGISTRY, "Searching '%S'\n", SearchKey->Name)); DbgPrint((DPRINT_REGISTRY, "Searching '%S'\n", SearchKey->Name));
if (SearchKey->NameSize == NameSize && CmpResult = _wcsnicmp(SearchKey->Name, name, subkeyLength);
_wcsnicmp(SearchKey->Name, name, subkeyLength) == 0) if (CmpResult == 0 && SearchKey->NameSize == NameSize)
break;
else if (CmpResult == 1)
break; break;
Ptr = Ptr->Flink; Ptr = Ptr->Flink;
} }
if (Ptr == &CurrentKey->SubKeyList) if (CmpResult != 0)
{ {
/* no key found -> create new subkey */ /* no key found -> create new subkey */
NewKey = (FRLDRHKEY)MmAllocateMemory(sizeof(KEY)); NewKey = (FRLDRHKEY)MmAllocateMemory(sizeof(KEY));
@ -294,7 +298,7 @@ RegCreateKey(FRLDRHKEY ParentKey,
NewKey->DataSize = 0; NewKey->DataSize = 0;
NewKey->Data = NULL; NewKey->Data = NULL;
InsertTailList(&CurrentKey->SubKeyList, &NewKey->KeyList); InsertTailList(Ptr, &NewKey->KeyList);
CurrentKey->SubKeyCount++; CurrentKey->SubKeyCount++;
NewKey->NameSize = NameSize; NewKey->NameSize = NameSize;

View file

@ -145,16 +145,32 @@ CmiAddKeyToHashTable(
IN HCELL_INDEX NKBOffset) IN HCELL_INDEX NKBOffset)
{ {
ULONG i = KeyCell->SubKeyCounts[StorageType]; ULONG i = KeyCell->SubKeyCounts[StorageType];
ULONG HashValue;
HashCell->Table[i].KeyOffset = NKBOffset;
HashCell->Table[i].HashValue = 0;
if (NewKeyCell->Flags & REG_KEY_NAME_PACKED) if (NewKeyCell->Flags & REG_KEY_NAME_PACKED)
{ {
RtlCopyMemory( RtlCopyMemory(
&HashCell->Table[i].HashValue, &HashValue,
NewKeyCell->Name, NewKeyCell->Name,
min(NewKeyCell->NameSize, sizeof(ULONG))); min(NewKeyCell->NameSize, sizeof(ULONG)));
} }
for (i = 0; i < KeyCell->SubKeyCounts[StorageType]; i++)
{
if (HashCell->Table[i].HashValue > HashValue)
break;
}
if (i < KeyCell->SubKeyCounts[StorageType])
{
RtlMoveMemory(HashCell->Table + i + 1,
HashCell->Table + i,
(HashCell->HashTableSize - 1 - i) *
sizeof(HashCell->Table[0]));
}
HashCell->Table[i].KeyOffset = NKBOffset;
HashCell->Table[i].HashValue = HashValue;
HvMarkCellDirty(&RegistryHive->Hive, KeyCell->SubKeyLists[StorageType]); HvMarkCellDirty(&RegistryHive->Hive, KeyCell->SubKeyLists[StorageType]);
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }