diff options
author | Andy Wingo <wingo@pobox.com> | 2012-02-22 20:40:55 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2012-02-22 20:40:55 +0100 |
commit | 7ea70f355e986c79f2c999753642141a0e8985f7 (patch) | |
tree | 48c4bc622d6990cb6031637132c532bf7a77626a /module/web/uri.scm | |
parent | 71cc8d96ee0917474c052fd484cad199be1311b2 (diff) | |
download | guile-7ea70f355e986c79f2c999753642141a0e8985f7.tar.gz |
microoptimizations in (web uri)
* module/web/uri.scm (valid-host?): Micro-optimizations.
Diffstat (limited to 'module/web/uri.scm')
-rw-r--r-- | module/web/uri.scm | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/module/web/uri.scm b/module/web/uri.scm index 1eb281380..a2a930a6a 100644 --- a/module/web/uri.scm +++ b/module/web/uri.scm @@ -1,6 +1,6 @@ ;;;; (web uri) --- URI manipulation tools ;;;; -;;;; Copyright (C) 1997,2001,2002,2010,2011 Free Software Foundation, Inc. +;;;; Copyright (C) 1997,2001,2002,2010,2011,2012 Free Software Foundation, Inc. ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -100,18 +100,17 @@ consistency checks to make sure that the constructed URI is valid." (define (valid-host? host) (cond ((regexp-exec ipv4-regexp host) - => (lambda (m) - (false-if-exception (inet-pton AF_INET (match:substring m 1))))) + (false-if-exception (inet-pton AF_INET host))) ((regexp-exec ipv6-regexp host) - => (lambda (m) - (false-if-exception (inet-pton AF_INET6 (match:substring m 1))))) + (false-if-exception (inet-pton AF_INET6 host))) (else - (let ((labels (reverse (string-split host #\.)))) - (and (pair? labels) - (regexp-exec top-label-regexp (car labels)) - (and-map (lambda (label) - (regexp-exec domain-label-regexp label)) - (cdr labels))))))) + (let lp ((start 0)) + (let ((end (string-index host #\. start))) + (if end + (and (regexp-exec domain-label-regexp + (substring host start end)) + (lp (1+ end))) + (regexp-exec top-label-regexp host start))))))) (define userinfo-pat "[a-zA-Z0-9_.!~*'();:&=+$,-]+") |