Binary search (upper bound) added by sytse on Tue Dec 10 09:28:59 2019

(put-appl 'char-set-contains? '(cset char) '\#ignore
  (lambda (cset ch)
    (unless (kernel-char-set? cset)
      (signal 'kernel-type-error (list 'char-set? cset)))
    (unless (kernel-char? ch)
      (signal 'kernel-type-error (list 'char? ch)))
    (setq cset (cddr cset))
    (setq ch (cdr ch))
    (if (eq cset [])
      ;; An 'upper bound' algorithm: find the location of
      ;; the first number that's bigger than ch.
      (let ((beg 0)
            (rem (length cset)))
        (while (> rem 0)
          (let* ((step   (/ rem 2))
                 (middle (+ beg step)))
            (if (<= (aref cset middle) ch)
                (setq beg (1+ middle)
                      rem (- rem (1+ step)))
              (setq rem step))))
        (if (eq (% beg 2) 0) '\#f '\#t)))))