From 13adb6230acff06da1ac98421d0ac72a65b746c3 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 10 Dec 2011 04:20:39 +0000 Subject: [PATCH] [USETUP] - Cache the last data block and offset so we don't have to search from the start each time - This avoids needless swapping of cabinet data in and out of RAM - File copy in text-mode setup on 32 MB RAM is down from 8 minutes to 20 seconds (in my testing) svn path=/trunk/; revision=54632 --- reactos/base/setup/usetup/cabinet.c | 19 +++++++++++++++---- reactos/base/setup/usetup/cabinet.h | 2 ++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/reactos/base/setup/usetup/cabinet.c b/reactos/base/setup/usetup/cabinet.c index 0ecb8be4f90..50821cdaa94 100644 --- a/reactos/base/setup/usetup/cabinet.c +++ b/reactos/base/setup/usetup/cabinet.c @@ -757,6 +757,12 @@ CabinetFindNext(PCAB_SEARCH Search) // FIXME: check for match against search criteria if (Search->File != Prev) { + if (Prev == NULL || Search->File->FolderIndex != Prev->FolderIndex) + { + Search->CFData = NULL; + Search->Offset = 0; + } + /* don't match the file we started with */ if (wcscmp(Search->Search, L"*") == 0) { @@ -1011,10 +1017,12 @@ CabinetExtractFile(PCAB_SEARCH Search) ExtractHandler(Search->File, DestName); } - /* find the starting block of the file - start with the first data block of the folder */ - CFData = (PCFDATA)(CabinetFolders[Search->File->FolderIndex].DataOffset + FileBuffer); - CurrentOffset = 0; + if (Search->CFData) + CFData = Search->CFData; + else + CFData = (PCFDATA)(CabinetFolders[Search->File->FolderIndex].DataOffset + FileBuffer); + + CurrentOffset = Search->Offset; while (CurrentOffset + CFData->UncompSize <= Search->File->FileOffset) { /* walk the data blocks until we reach @@ -1022,6 +1030,9 @@ CabinetExtractFile(PCAB_SEARCH Search) CurrentOffset += CFData->UncompSize; CFData = (PCFDATA)((char *)(CFData + 1) + DataReserved + CFData->CompSize); } + + Search->CFData = CFData; + Search->Offset = CurrentOffset; /* now decompress and discard any data in the block before the start of the file */ diff --git a/reactos/base/setup/usetup/cabinet.h b/reactos/base/setup/usetup/cabinet.h index 98d175c6f98..096504524ad 100644 --- a/reactos/base/setup/usetup/cabinet.h +++ b/reactos/base/setup/usetup/cabinet.h @@ -108,6 +108,8 @@ typedef struct _CAB_SEARCH WCHAR Cabinet[MAX_PATH]; USHORT Index; PCFFILE File; // Pointer to current CFFILE + PCFDATA CFData; + ULONG Offset; } CAB_SEARCH, *PCAB_SEARCH;