Currently, equal() does the following for List nodes:
case T_List:
{
List *la = (List *) a;
List *lb = (List *) b;
List *l;
/*
* Try to reject by length check before we grovel through
* all the elements...
*/
if (length(la) != length(lb))
return false;
foreach(l, la)
{
if (!equal(lfirst(l), lfirst(lb)))
return false;
lb = lnext(lb);
}
retval = true;
}
break;
This code is inefficient, however: length() requires iterating through
the entire list, so this code scans both lists twice. The attached patch
improves this by implementing equal() with a single scan of both lists.
-Neil