msi: Optimize MsiSourceListAddSourceEx for adding to the end of the list.

This commit is contained in:
James Hawkins 2008-03-10 23:02:02 -05:00 committed by Alexandre Julliard
parent 0118e0d0f1
commit 5871bee8c7
1 changed files with 13 additions and 8 deletions

View File

@ -934,12 +934,15 @@ static void free_source_list(struct list *sourcelist)
} }
} }
static void add_source_to_list(struct list *sourcelist, media_info *info) static void add_source_to_list(struct list *sourcelist, media_info *info,
DWORD *index)
{ {
media_info *iter; media_info *iter;
BOOL found = FALSE; BOOL found = FALSE;
static const WCHAR fmt[] = {'%','i',0}; static const WCHAR fmt[] = {'%','i',0};
if (index) *index = 0;
if (list_empty(sourcelist)) if (list_empty(sourcelist))
{ {
list_add_head(sourcelist, &info->entry); list_add_head(sourcelist, &info->entry);
@ -957,6 +960,8 @@ static void add_source_to_list(struct list *sourcelist, media_info *info)
/* update the rest of the list */ /* update the rest of the list */
if (found) if (found)
sprintfW(iter->szIndex, fmt, ++iter->index); sprintfW(iter->szIndex, fmt, ++iter->index);
else if (index)
(*index)++;
} }
if (!found) if (!found)
@ -1005,7 +1010,7 @@ static UINT fill_source_list(struct list *sourcelist, HKEY sourcekey, DWORD *cou
} }
index = ++(*count); index = ++(*count);
add_source_to_list(sourcelist, entry); add_source_to_list(sourcelist, entry, NULL);
} }
error: error:
@ -1031,6 +1036,7 @@ UINT WINAPI MsiSourceListAddSourceExW( LPCWSTR szProduct, LPCWSTR szUserSid,
LPWSTR source; LPWSTR source;
LPCWSTR postfix; LPCWSTR postfix;
DWORD size, count; DWORD size, count;
DWORD index;
static const WCHAR fmt[] = {'%','i',0}; static const WCHAR fmt[] = {'%','i',0};
static const WCHAR one[] = {'1',0}; static const WCHAR one[] = {'1',0};
@ -1098,7 +1104,7 @@ UINT WINAPI MsiSourceListAddSourceExW( LPCWSTR szProduct, LPCWSTR szUserSid,
rc = RegSetValueExW(typekey, one, 0, REG_EXPAND_SZ, (LPBYTE)source, size); rc = RegSetValueExW(typekey, one, 0, REG_EXPAND_SZ, (LPBYTE)source, size);
goto done; goto done;
} }
else if (dwIndex > count) else if (dwIndex > count || dwIndex == 0)
{ {
sprintfW(name, fmt, count + 1); sprintfW(name, fmt, count + 1);
rc = RegSetValueExW(typekey, name, 0, REG_EXPAND_SZ, (LPBYTE)source, size); rc = RegSetValueExW(typekey, name, 0, REG_EXPAND_SZ, (LPBYTE)source, size);
@ -1106,10 +1112,6 @@ UINT WINAPI MsiSourceListAddSourceExW( LPCWSTR szProduct, LPCWSTR szUserSid,
} }
else else
{ {
/* add to the end of the list */
if (dwIndex == 0)
dwIndex = count + 1;
sprintfW(name, fmt, dwIndex); sprintfW(name, fmt, dwIndex);
info = msi_alloc(sizeof(media_info)); info = msi_alloc(sizeof(media_info));
if (!info) if (!info)
@ -1121,10 +1123,13 @@ UINT WINAPI MsiSourceListAddSourceExW( LPCWSTR szProduct, LPCWSTR szUserSid,
info->path = strdupW(source); info->path = strdupW(source);
lstrcpyW(info->szIndex, name); lstrcpyW(info->szIndex, name);
info->index = dwIndex; info->index = dwIndex;
add_source_to_list(&sourcelist, info); add_source_to_list(&sourcelist, info, &index);
LIST_FOR_EACH_ENTRY(info, &sourcelist, media_info, entry) LIST_FOR_EACH_ENTRY(info, &sourcelist, media_info, entry)
{ {
if (info->index < index)
continue;
size = (lstrlenW(info->path) + 1) * sizeof(WCHAR); size = (lstrlenW(info->path) + 1) * sizeof(WCHAR);
rc = RegSetValueExW(typekey, info->szIndex, 0, rc = RegSetValueExW(typekey, info->szIndex, 0,
REG_EXPAND_SZ, (LPBYTE)info->path, size); REG_EXPAND_SZ, (LPBYTE)info->path, size);