(define-integrable (zero! j o)
(primitive-byte-set! to (fix:+ j o) 0))
- (case (ustring-cp-size from)
- ((1)
- (let ((start (cp1-index start))
- (end (cp1-index end)))
- (case (ustring-cp-size to)
- ((1)
- (do ((i start (fix:+ i 1))
- (j (cp1-index at) (fix:+ j 1)))
- ((not (fix:< i end)))
- (copy! j i 0)))
- ((2)
- (do ((i start (fix:+ i 1))
- (j (cp2-index at) (fix:+ j 2)))
- ((not (fix:< i end)))
- (copy! j i 0)
- (zero! j 1)))
- (else
- (do ((i start (fix:+ i 1))
- (j (cp3-index at) (fix:+ j 3)))
- ((not (fix:< i end)))
- (copy! j i 0)
- (zero! j 1)
- (zero! j 2))))))
- ((2)
- (let ((start (cp2-index start))
- (end (cp2-index end)))
- (case (ustring-cp-size to)
- ((1)
- (do ((i start (fix:+ i 2))
- (j (cp1-index at) (fix:+ j 1)))
- ((not (fix:< i end)))
- (copy! j i 0)))
- ((2)
- (do ((i start (fix:+ i 2))
- (j (cp2-index at) (fix:+ j 2)))
- ((not (fix:< i end)))
- (copy! j i 0)
- (copy! j i 1)))
- (else
- (do ((i start (fix:+ i 2))
- (j (cp3-index at) (fix:+ j 3)))
- ((not (fix:< i end)))
- (copy! j i 0)
- (copy! j i 1)
- (zero! j 2))))))
- (else
- (let ((start (cp3-index start))
- (end (cp3-index end)))
- (case (ustring-cp-size to)
- ((1)
- (do ((i start (fix:+ i 3))
- (j (cp1-index at) (fix:+ j 1)))
- ((not (fix:< i end)))
- (copy! j i 0)))
- ((2)
- (do ((i start (fix:+ i 3))
- (j (cp2-index at) (fix:+ j 2)))
- ((not (fix:< i end)))
- (copy! j i 0)
- (copy! j i 1)))
- (else
- (do ((i start (fix:+ i 3))
- (j (cp3-index at) (fix:+ j 3)))
- ((not (fix:< i end)))
- (copy! j i 0)
- (copy! j i 1)
- (copy! j i 2))))))))
+ (if (eq? to from)
+ (%general-shift! to at start end)
+ (case (ustring-cp-size from)
+ ((1)
+ (let ((start (cp1-index start))
+ (end (cp1-index end)))
+ (case (ustring-cp-size to)
+ ((1)
+ (do ((i start (fix:+ i 1))
+ (j (cp1-index at) (fix:+ j 1)))
+ ((not (fix:< i end)))
+ (copy! j i 0)))
+ ((2)
+ (do ((i start (fix:+ i 1))
+ (j (cp2-index at) (fix:+ j 2)))
+ ((not (fix:< i end)))
+ (copy! j i 0)
+ (zero! j 1)))
+ (else
+ (do ((i start (fix:+ i 1))
+ (j (cp3-index at) (fix:+ j 3)))
+ ((not (fix:< i end)))
+ (copy! j i 0)
+ (zero! j 1)
+ (zero! j 2))))))
+ ((2)
+ (let ((start (cp2-index start))
+ (end (cp2-index end)))
+ (case (ustring-cp-size to)
+ ((1)
+ (do ((i start (fix:+ i 2))
+ (j (cp1-index at) (fix:+ j 1)))
+ ((not (fix:< i end)))
+ (copy! j i 0)))
+ ((2)
+ (do ((i start (fix:+ i 2))
+ (j (cp2-index at) (fix:+ j 2)))
+ ((not (fix:< i end)))
+ (copy! j i 0)
+ (copy! j i 1)))
+ (else
+ (do ((i start (fix:+ i 2))
+ (j (cp3-index at) (fix:+ j 3)))
+ ((not (fix:< i end)))
+ (copy! j i 0)
+ (copy! j i 1)
+ (zero! j 2))))))
+ (else
+ (let ((start (cp3-index start))
+ (end (cp3-index end)))
+ (case (ustring-cp-size to)
+ ((1)
+ (do ((i start (fix:+ i 3))
+ (j (cp1-index at) (fix:+ j 1)))
+ ((not (fix:< i end)))
+ (copy! j i 0)))
+ ((2)
+ (do ((i start (fix:+ i 3))
+ (j (cp2-index at) (fix:+ j 2)))
+ ((not (fix:< i end)))
+ (copy! j i 0)
+ (copy! j i 1)))
+ (else
+ (do ((i start (fix:+ i 3))
+ (j (cp3-index at) (fix:+ j 3)))
+ ((not (fix:< i end)))
+ (copy! j i 0)
+ (copy! j i 1)
+ (copy! j i 2)))))))))
\f
+(define (%general-shift! ustring to start end)
+ (cond ((fix:< to start) (%shift-left! ustring to start end))
+ ((fix:> to start) (%shift-right! ustring to start end))))
+
+(define (%shift-left! ustring to start end)
+
+ (define (do-shift! to start end)
+ (do ((i start (fix:+ i 1))
+ (j to (fix:+ j 1)))
+ ((not (fix:< i end)))
+ (primitive-byte-set! ustring j (primitive-byte-ref ustring i))))
+
+ (case (ustring-cp-size ustring)
+ ((1) (do-shift! (cp1-index to) (cp1-index start) (cp1-index end)))
+ ((2) (do-shift! (cp2-index to) (cp2-index start) (cp2-index end)))
+ (else (do-shift! (cp3-index to) (cp3-index start) (cp3-index end)))))
+
+(define (%shift-right! ustring to start end)
+
+ (define (do-shift! to start end)
+ (do ((i (fix:- end 1) (fix:- i 1))
+ (j (fix:- (fix:+ to (fix:- end start)) 1) (fix:- j 1)))
+ ((not (fix:>= i start)))
+ (primitive-byte-set! ustring j (primitive-byte-ref ustring i))))
+
+ (case (ustring-cp-size ustring)
+ ((1) (do-shift! (cp1-index to) (cp1-index start) (cp1-index end)))
+ ((2) (do-shift! (cp2-index to) (cp2-index start) (cp2-index end)))
+ (else (do-shift! (cp3-index to) (cp3-index start) (cp3-index end)))))
+
(define (%general-max-cp string start end)
(define-integrable (max-loop cp-ref)