Made ECMA-119 tree sorting deterministic with different qsort implementations. By Henrik Lindström.
This commit is contained in:
parent
efaab52265
commit
3a43995fb5
@ -595,6 +595,28 @@ int cmp_node_name(const void *f1, const void *f2)
|
|||||||
return strcmp(f->iso_name, g->iso_name);
|
return strcmp(f->iso_name, g->iso_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare the iso name of two ECMA-119 nodes, without equivalences.
|
||||||
|
* Nodes with equal iso names are instead ordered by their real names.
|
||||||
|
*
|
||||||
|
* This is used to make the initial tree sort deterministic, before
|
||||||
|
* iso names are mangled to become unique.
|
||||||
|
*/
|
||||||
|
static
|
||||||
|
int cmp_node_name_tiebreak(const void *f1, const void *f2)
|
||||||
|
{
|
||||||
|
Ecma119Node *f, *g;
|
||||||
|
int cmp;
|
||||||
|
|
||||||
|
cmp = cmp_node_name(f1, f2);
|
||||||
|
if (cmp)
|
||||||
|
return cmp;
|
||||||
|
|
||||||
|
f = *((Ecma119Node**)f1);
|
||||||
|
g = *((Ecma119Node**)f2);
|
||||||
|
return strcmp(f->node->name, g->node->name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts a the children of each directory in the ECMA-119 tree represented
|
* Sorts a the children of each directory in the ECMA-119 tree represented
|
||||||
* by \p root, according to the order specified in ECMA-119, section 9.3.
|
* by \p root, according to the order specified in ECMA-119, section 9.3.
|
||||||
@ -607,7 +629,7 @@ void sort_tree(Ecma119Node *root)
|
|||||||
if (root->info.dir->children == NULL)
|
if (root->info.dir->children == NULL)
|
||||||
return;
|
return;
|
||||||
qsort(root->info.dir->children, root->info.dir->nchildren, sizeof(void*),
|
qsort(root->info.dir->children, root->info.dir->nchildren, sizeof(void*),
|
||||||
cmp_node_name);
|
cmp_node_name_tiebreak);
|
||||||
for (i = 0; i < root->info.dir->nchildren; i++) {
|
for (i = 0; i < root->info.dir->nchildren; i++) {
|
||||||
if (root->info.dir->children[i]->type == ECMA119_DIR)
|
if (root->info.dir->children[i]->type == ECMA119_DIR)
|
||||||
sort_tree(root->info.dir->children[i]);
|
sort_tree(root->info.dir->children[i]);
|
||||||
|
Loading…
Reference in New Issue
Block a user