From a13070f3022dd0764e58064b9367c0897b585228 Mon Sep 17 00:00:00 2001 From: Ben Greenman Date: Wed, 1 May 2019 23:35:27 -0400 Subject: [PATCH] racket/contract: improve `fast-append` test whether the 2nd arg is null once, rather than N times --- .../racket/contract/private/collapsible-common.rkt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/racket/collects/racket/contract/private/collapsible-common.rkt b/racket/collects/racket/contract/private/collapsible-common.rkt index e66acf9d89..144617403f 100644 --- a/racket/collects/racket/contract/private/collapsible-common.rkt +++ b/racket/collects/racket/contract/private/collapsible-common.rkt @@ -217,11 +217,12 @@ ;; A specialized version of append that will immediately return if either ;; argument is empty (define (fast-append l1 l2) - (cond - [(null? l2) l1] - [(null? l1) l2] - [else - (cons (car l1) (fast-append (cdr l1) l2))])) + (if (null? l2) + l1 + (let fast-append ((l1 l1)) + (if (null? l1) + l2 + (cons (car l1) (fast-append (cdr l1))))))) ;; Assuming that merging is symmetric, ie old-can-merge? iff new-can-merge? ;; This is true of the current c-c implementation, but if it ever changes