mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-16 09:17:35 +02:00
Massive speedup comparing certain types of lists
This commit is contained in:
parent
19f6f73fbb
commit
13ce612768
1 changed files with 12 additions and 3 deletions
11
runtime.c
11
runtime.c
|
@ -877,11 +877,13 @@ object memqp(void *data, object x, list l)
|
|||
}
|
||||
|
||||
/**
|
||||
* Check two objects for deep equality
|
||||
*/
|
||||
object equalp(object x, object y)
|
||||
{
|
||||
object slow_lis = x, fast_lis = NULL;
|
||||
int second_cycle = 0;
|
||||
object slow_lis = x, fast_lis = NULL;
|
||||
object pcar_x = &second_cycle, pcar_y = &second_cycle; // never a car value
|
||||
|
||||
if (Cyc_is_pair(x) == boolean_t &&
|
||||
Cyc_is_pair(cdr(x)) == boolean_t){
|
||||
|
@ -897,8 +899,15 @@ object equalp(object x, object y)
|
|||
return boolean_f;
|
||||
|
||||
// Both objects are lists at this point, compare cars
|
||||
if (pcar_x == car(x) &&
|
||||
pcar_y == car(y)) {
|
||||
// do nothing, already equal
|
||||
} else {
|
||||
if (boolean_f == equalp(car(x), car(y)))
|
||||
return boolean_f;
|
||||
pcar_x = car(x);
|
||||
pcar_y = car(y);
|
||||
}
|
||||
|
||||
// If there is no cycle, keep checking equality
|
||||
if (fast_lis == NULL ||
|
||||
|
|
Loading…
Add table
Reference in a new issue