(define-integrable (%substring-find-next-char-in-set string start end char-set)
((ucode-primitive substring-find-next-char-in-set)
- string start end (cached-char-set-table char-set)))
+ string start end (char-set-table char-set)))
(define (string-find-previous-char-in-set string char-set)
(guarantee-string string 'STRING-FIND-PREVIOUS-CHAR-IN-SET)
(define (%substring-find-previous-char-in-set string start end char-set)
((ucode-primitive substring-find-previous-char-in-set)
- string start end (cached-char-set-table char-set)))
-
-;; Kludge! These used to be cached in the record when the char-set was
-;; constructed; now they are not.
-
-(define char-set-table-lock
- (make-thread-mutex))
-
-(define char-set-table-table
- (make-weak-eq-hash-table))
-
-(define (cached-char-set-table char-set)
- (or (begin (lock-thread-mutex char-set-table-lock)
- (begin0 (hash-table-ref char-set-table-table char-set (lambda () #f))
- (unlock-thread-mutex char-set-table-lock)))
- (let ((table (char-set-table char-set)))
- (lock-thread-mutex char-set-table-lock)
- ;; If we raced with someone else, no problem -- if there's a
- ;; duplicate table then it'll be GC'd at the end.
- (hash-table-set! char-set-table-table char-set table)
- (unlock-thread-mutex char-set-table-lock)
- table)))
+ string start end (char-set-table char-set)))
\f
;;;; String search
;;; The HIGH range sequence is a u24 bytevector implementing an inversion list.
(define-record-type <char-set>
- (%make-char-set low high predicate)
+ (%make-char-set low high predicate table)
char-set?
(low %char-set-low)
(high %char-set-high)
- (predicate %char-set-predicate))
+ (predicate %char-set-predicate)
+ ;; backwards compatibility for Edwin:
+ (table %char-set-table))
(define (make-char-set low high)
(letrec
(and (char? char)
(char-in-set? char char-set)))))
(register-predicate! predicate 'char-set-predicate '<= char?)
- predicate)))))
+ predicate))
+ (delay
+ (let ((table (make-bytevector #x100)))
+ (do ((cp 0 (fix:+ cp 1)))
+ ((not (fix:< cp #x100)))
+ (bytevector-u8-set! table cp
+ (if (%code-point-in-char-set? cp char-set)
+ 1
+ 0)))
+ table)))))
char-set))
(define-integrable %low-cps-per-byte 8)
(define (char-set-predicate char-set)
(force (%char-set-predicate char-set)))
+(define (char-set-table char-set)
+ (force (%char-set-table char-set)))
+
(define (char-set=? char-set . char-sets)
(every (lambda (char-set*)
(and (bytevector=? (%char-set-low char-set*)
(error:bad-range-argument end 'ascii-range->char-set))
(char-set (cons start end)))
-(define (%char-set-table char-set)
- (let ((table (make-bytevector #x100)))
- (do ((cp 0 (fix:+ cp 1)))
- ((not (fix:< cp #x100)))
- (bytevector-u8-set! table cp
- (if (%code-point-in-char-set? cp char-set) 1 0)))
- table))
-
(define (8-bit-char-set? char-set)
(and (char-set? char-set)
(let ((high (%char-set-high char-set)))