Ignore:
Timestamp:
09/08/18 12:12:54 (5 weeks ago)
Author:
sjamaan
Message:

uri-generic: Drop unnecessary dependency on srfi-13

We used only three procedures: string-index, string-upcase and string-downcase.
string-index can be replaced relatively easily using substring-index, which is
implemented as memcmp so it might be even faster. string-upcase and
string-downcase are trivially re-implemented and for percent encoded characters
we even did this on a string which we know has only one character (in hex-digit),
so it's pointless to convert back and forth between a list, which is what these
procedures do. Instead, just take the one char and upcase it.

This should provide a (minor) performance benefit, besides dropping the useless
dependency.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/5/uri-generic/trunk/alternatives/uri-generic.abnf.scm

    r33645 r36551  
    4343;; What to do with these?
    4444;; #;(cond-expand
    45 ;;    (utf8-strings (use utf8-srfi-13 utf8-srfi-14))
    46 ;;    (else (use srfi-13 srfi-14)))
     45;;    (utf8-strings (use utf8-srfi-14))
     46;;    (else (use srfi-14)))
    4747
    4848(define-record-type <URI>
     
    382382
    383383;; Section 4.2; if the first segment contains a colon, it must be prefixed "./"
    384 (define (protect? sa) (string-index sa #\:))
     384(define (protect? sa) (substring-index ":" sa))
    385385
    386386; specific: ((uri-authority uri) (uri-path uri) (uri-query uri)).
     
    401401
    402402(define (uri-normalize-case uri)
    403   (let* ((normalized-uri (uri-reference
     403  (let* ((downcase (lambda (s)
     404                     (list->string (map char-downcase (string->list s)))))
     405         (normalized-uri (uri-reference
    404406                          (normalize-pct-encoding (uri->string uri (lambda (user pass) (conc user ":" pass))))))
    405          (scheme         (string->symbol (string-downcase (->string (uri-scheme uri)))))
    406          (host           (normalize-pct-encoding (string-downcase (uri-host uri)))))
     407         (scheme         (string->symbol (downcase (->string (uri-scheme uri)))))
     408         (host           (normalize-pct-encoding (downcase (uri-host uri)))))
    407409    (update-uri* normalized-uri 'scheme scheme 'host host)))
    408410
     
    422424  (define (hex-digit i)
    423425    (and (>= i 0) (< i 16)
    424          (car (string->list (string-upcase (number->string i 16))))))
     426         (char-upcase (string-ref (number->string i 16) 0))))
    425427  (define (pct-encode c)
    426428    (let ((i (char->integer c)))
Note: See TracChangeset for help on using the changeset viewer.