Owen Rudge orudge@codeweavers.com writes:
+static LPWSTR generate_namespace_prefix(struct list *namespaces, void *parentMemoryBlock, LPCWSTR uri) +{
- WCHAR formatString[] = { 'u','n','%','d', 0 };
- WCHAR suggestedPrefix[7];
- int i;
- ZeroMemory(suggestedPrefix, sizeof(suggestedPrefix));
- /* Find a unique prefix */
- for (i = 0; i < 1000; i++)
- {
wsprintfW(suggestedPrefix, formatString, i);
if (is_prefix_unique(namespaces, suggestedPrefix))
{
return duplicate_string(parentMemoryBlock, suggestedPrefix);
}
- }
This looks extremely inefficient.
On 17/05/2017 18:04, Alexandre Julliard wrote:
This looks extremely inefficient.
I've reworked this slightly so that it'll now keep track of the next expected prefix number. In the vast majority of cases, therefore, only one iteration of the namespace list will be required. Usually a WSD XML context will not contain more than 3 or 4 namespaces at any rate.
We still need to check for uniqueness, as it is possible that a user could explicitly create a namespace prefix called "un4", for instance. I've added a test to show that the behaviour of my patch matches that of Windows.