From d8c3edd3e16849f7806c390f75a8ed5ab5e791ba Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Tue, 11 Jun 2019 18:38:19 -0600 Subject: [PATCH] io: tiny performance tweak for path-element checking --- racket/src/io/path/main.rkt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/racket/src/io/path/main.rkt b/racket/src/io/path/main.rkt index cc3111dd30..c745df4ce1 100644 --- a/racket/src/io/path/main.rkt +++ b/racket/src/io/path/main.rkt @@ -91,14 +91,15 @@ (check-path-bytes who bstr) (do-bytes->path-element bstr convention who bstr)) -(define (path-element-clean p) +(define (path-element-clean p #:try-quick? [try-quick? #f]) (cond [(path? p) (define bstr (path-bytes p)) (define convention (path-convention p)) (and ;; Quick pre-check: any separators that are not at the end? - (or (not (eq? convention 'unix)) + (or (not try-quick?) + (not (eq? convention 'unix)) (not (for/or ([c (in-bytes bstr 0 (let loop ([end (bytes-length bstr)]) (cond [(zero? end) 0] @@ -115,7 +116,7 @@ [else #f])) (define (path-element? p) - (and (path-element-clean p) #t)) + (and (path-element-clean p #:try-quick? #t) #t)) (define (do-bytes->path-element bstr convention who orig-arg) (define (bad-element)