From 8f044e38806db6ab87db08d2c6061e6e6efe8170 Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Mon, 12 Sep 2011 18:12:24 -0400 Subject: [PATCH] Compare numeric unions using a linear scan. original commit: 8ae1a903fa8703e86e3225b098ba0f3a5537eb9f --- collects/typed-racket/types/subtype.rkt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/collects/typed-racket/types/subtype.rkt b/collects/typed-racket/types/subtype.rkt index 65da3232..72417e20 100644 --- a/collects/typed-racket/types/subtype.rkt +++ b/collects/typed-racket/types/subtype.rkt @@ -367,11 +367,17 @@ [((Union: l1) (Union: l2)) (=> unmatch) (if (and (eq? ks 'number) (eq? kt 'number)) - (if (for/and ([elem1 (in-list l1)]) - ;; since the lists are sorted, this could be optimized further - (memq elem1 l2)) - A0 - (fail! s t)) + ;; l1 should be a subset of l2 + ;; since union elements are sorted, a linear scan works + (let loop ([l1 l1] [l2 l2]) + (cond [(null? l1) + A0] + [(null? l2) + (fail! s t)] + [(eq? (car l1) (car l2)) + (loop (cdr l1) (cdr l2))] + [else + (loop l1 (cdr l2))])) (unmatch))] [((Union: (list e1 e2)) t) (if (and (subtype* A0 e1 t) (subtype* A0 e2 t))