gdi32: Avoid some redundant registry calls while loading the font cache.

oldstable
Alexandre Julliard 2012-11-01 12:35:32 +01:00
parent 3d013afec7
commit c1f8a0bf61
1 changed files with 45 additions and 65 deletions

View File

@ -1298,11 +1298,15 @@ static Family *create_family( WCHAR *name, WCHAR *english_name )
static LONG reg_load_dword(HKEY hkey, const WCHAR *value, DWORD *data) static LONG reg_load_dword(HKEY hkey, const WCHAR *value, DWORD *data)
{ {
DWORD type, needed; DWORD type, size = sizeof(DWORD);
LONG r = RegQueryValueExW(hkey, value, NULL, &type, NULL, &needed);
if(r != ERROR_SUCCESS) return r; if (RegQueryValueExW(hkey, value, NULL, &type, (BYTE *)data, &size) ||
if(type != REG_DWORD || needed != sizeof(DWORD)) return ERROR_BAD_CONFIGURATION; type != REG_DWORD || size != sizeof(DWORD))
return RegQueryValueExW(hkey, value, NULL, &type, (BYTE*)data, &needed); {
*data = 0;
return ERROR_BAD_CONFIGURATION;
}
return ERROR_SUCCESS;
} }
static inline LONG reg_save_dword(HKEY hkey, const WCHAR *value, DWORD data) static inline LONG reg_save_dword(HKEY hkey, const WCHAR *value, DWORD data)
@ -1310,30 +1314,26 @@ static inline LONG reg_save_dword(HKEY hkey, const WCHAR *value, DWORD data)
return RegSetValueExW(hkey, value, 0, REG_DWORD, (BYTE*)&data, sizeof(DWORD)); return RegSetValueExW(hkey, value, 0, REG_DWORD, (BYTE*)&data, sizeof(DWORD));
} }
static void load_face(HKEY hkey_face, WCHAR *face_name, Family *family) static void load_face(HKEY hkey_face, WCHAR *face_name, Family *family, void *buffer, DWORD buffer_size)
{ {
DWORD needed; DWORD needed, strike_index = 0;
DWORD num_strikes, max_strike_key_len; HKEY hkey_strike;
/* If we have a File Name key then this is a real font, not just the parent /* If we have a File Name key then this is a real font, not just the parent
key of a bunch of non-scalable strikes */ key of a bunch of non-scalable strikes */
if(RegQueryValueExA(hkey_face, "File Name", NULL, NULL, NULL, &needed) == ERROR_SUCCESS) needed = buffer_size;
if(RegQueryValueExA(hkey_face, "File Name", NULL, NULL, buffer, &needed) == ERROR_SUCCESS)
{ {
Face *face; Face *face;
face = HeapAlloc(GetProcessHeap(), 0, sizeof(*face)); face = HeapAlloc(GetProcessHeap(), 0, sizeof(*face));
face->cached_enum_data = NULL; face->cached_enum_data = NULL;
face->file = HeapAlloc(GetProcessHeap(), 0, needed); face->file = strdupA( buffer );
RegQueryValueExA(hkey_face, "File Name", NULL, NULL, (BYTE*)face->file, &needed);
face->StyleName = strdupW(face_name); face->StyleName = strdupW(face_name);
if(RegQueryValueExW(hkey_face, face_full_name_value, NULL, NULL, NULL, &needed) == ERROR_SUCCESS) needed = buffer_size;
{ if(RegQueryValueExW(hkey_face, face_full_name_value, NULL, NULL, buffer, &needed) == ERROR_SUCCESS)
WCHAR *fullName = HeapAlloc(GetProcessHeap(), 0, needed); face->FullName = strdupW( buffer );
RegQueryValueExW(hkey_face, face_full_name_value, NULL, NULL, (BYTE*)fullName, &needed);
face->FullName = fullName;
}
else else
face->FullName = NULL; face->FullName = NULL;
@ -1374,57 +1374,41 @@ static void load_face(HKEY hkey_face, WCHAR *face_name, Family *family)
TRACE("Added font %s %s\n", debugstr_w(family->FamilyName), debugstr_w(face->StyleName)); TRACE("Added font %s %s\n", debugstr_w(family->FamilyName), debugstr_w(face->StyleName));
} }
/* do we have any bitmap strikes? */ /* load bitmap strikes */
RegQueryInfoKeyW(hkey_face, NULL, NULL, NULL, &num_strikes, &max_strike_key_len, NULL, NULL,
NULL, NULL, NULL, NULL);
if(num_strikes != 0)
{
WCHAR strike_name[10];
DWORD strike_index = 0;
needed = sizeof(strike_name) / sizeof(WCHAR); needed = buffer_size;
while(RegEnumKeyExW(hkey_face, strike_index++, strike_name, &needed, while (!RegEnumKeyExW(hkey_face, strike_index++, buffer, &needed, NULL, NULL, NULL, NULL))
NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
if (!RegOpenKeyExW(hkey_face, buffer, 0, KEY_ALL_ACCESS, &hkey_strike))
{ {
HKEY hkey_strike; load_face(hkey_strike, face_name, family, buffer, buffer_size);
RegOpenKeyExW(hkey_face, strike_name, 0, KEY_ALL_ACCESS, &hkey_strike);
load_face(hkey_strike, face_name, family);
RegCloseKey(hkey_strike); RegCloseKey(hkey_strike);
needed = sizeof(strike_name) / sizeof(WCHAR);
} }
needed = buffer_size;
} }
} }
static void load_font_list_from_cache(HKEY hkey_font_cache) static void load_font_list_from_cache(HKEY hkey_font_cache)
{ {
DWORD max_family_key_len, size; DWORD size, family_index = 0;
WCHAR *family_name;
DWORD family_index = 0;
Family *family; Family *family;
HKEY hkey_family; HKEY hkey_family;
WCHAR buffer[4096];
RegQueryInfoKeyW(hkey_font_cache, NULL, NULL, NULL, NULL, &max_family_key_len, NULL, NULL, size = sizeof(buffer);
NULL, NULL, NULL, NULL); while (!RegEnumKeyExW(hkey_font_cache, family_index++, buffer, &size, NULL, NULL, NULL, NULL))
family_name = HeapAlloc(GetProcessHeap(), 0, (max_family_key_len + 1) * sizeof(WCHAR));
size = max_family_key_len + 1;
while(RegEnumKeyExW(hkey_font_cache, family_index++, family_name, &size,
NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
{ {
WCHAR *english_family = NULL; WCHAR *english_family = NULL;
WCHAR *family_name = strdupW( buffer );
DWORD face_index = 0; DWORD face_index = 0;
WCHAR *face_name;
DWORD max_face_key_len;
RegOpenKeyExW(hkey_font_cache, family_name, 0, KEY_ALL_ACCESS, &hkey_family); RegOpenKeyExW(hkey_font_cache, family_name, 0, KEY_ALL_ACCESS, &hkey_family);
TRACE("opened family key %s\n", debugstr_w(family_name)); TRACE("opened family key %s\n", debugstr_w(family_name));
if(RegQueryValueExW(hkey_family, english_name_value, NULL, NULL, NULL, &size) == ERROR_SUCCESS) size = sizeof(buffer);
{ if (!RegQueryValueExW(hkey_family, english_name_value, NULL, NULL, (BYTE *)buffer, &size))
english_family = HeapAlloc(GetProcessHeap(), 0, size); english_family = strdupW( buffer );
RegQueryValueExW(hkey_family, english_name_value, NULL, NULL, (BYTE*)english_family, &size);
}
family = create_family(strdupW(family_name), english_family); family = create_family(family_name, english_family);
list_add_tail(&font_list, &family->entry); list_add_tail(&font_list, &family->entry);
if(english_family) if(english_family)
@ -1437,27 +1421,23 @@ static void load_font_list_from_cache(HKEY hkey_font_cache)
add_font_subst(&font_subst_list, subst, 0); add_font_subst(&font_subst_list, subst, 0);
} }
RegQueryInfoKeyW(hkey_family, NULL, NULL, NULL, NULL, &max_face_key_len, NULL, NULL, size = sizeof(buffer);
NULL, NULL, NULL, NULL); while (!RegEnumKeyExW(hkey_family, face_index++, buffer, &size, NULL, NULL, NULL, NULL))
face_name = HeapAlloc(GetProcessHeap(), 0, (max_face_key_len + 1) * sizeof(WCHAR));
size = max_face_key_len + 1;
while(RegEnumKeyExW(hkey_family, face_index++, face_name, &size,
NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
{ {
WCHAR *face_name = strdupW( buffer );
HKEY hkey_face; HKEY hkey_face;
RegOpenKeyExW(hkey_family, face_name, 0, KEY_ALL_ACCESS, &hkey_face); if (!RegOpenKeyExW(hkey_family, face_name, 0, KEY_ALL_ACCESS, &hkey_face))
load_face(hkey_face, face_name, family); {
RegCloseKey(hkey_face); load_face(hkey_face, face_name, family, buffer, sizeof(buffer));
size = max_face_key_len + 1; RegCloseKey(hkey_face);
}
HeapFree( GetProcessHeap(), 0, face_name );
size = sizeof(buffer);
} }
HeapFree(GetProcessHeap(), 0, face_name);
RegCloseKey(hkey_family); RegCloseKey(hkey_family);
size = max_family_key_len + 1; size = sizeof(buffer);
} }
HeapFree(GetProcessHeap(), 0, family_name);
} }
static LONG create_font_cache_key(HKEY *hkey, DWORD *disposition) static LONG create_font_cache_key(HKEY *hkey, DWORD *disposition)