gcl.git - GNU Common Lisp

index : gcl.git
GNU Common Lisp
summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamm Maguire <camm@debian.org>2014年09月17日 11:51:29 -0400
committerCamm Maguire <camm@debian.org>2014年09月18日 10:00:22 -0400
commitd995bdc03f4a3d57933284ae315db8900b478119 (patch)
treea8cb04800ee0312d5a29480578ba90a1166b0c7a
parentfec60cce4145c053eea0f3d87b4f4a112e503153 (diff)
downloadgcl-d995bdc03f4a3d57933284ae315db8900b478119.tar.gz
faster adjust-array
Diffstat
-rwxr-xr-xgcl/lsp/gcl_arraylib.lsp 106
1 files changed, 46 insertions, 60 deletions
diff --git a/gcl/lsp/gcl_arraylib.lsp b/gcl/lsp/gcl_arraylib.lsp
index 0d2bb5f2e..135bac839 100755
--- a/gcl/lsp/gcl_arraylib.lsp
+++ b/gcl/lsp/gcl_arraylib.lsp
@@ -261,73 +261,59 @@
(aref vector (the fixnum (1- fp)))))
+(defun maset (array x dim &optional (cx (cons x -1)) (cur (make-list (length dim) :initial-element 0)) (ind cur))
+ (declare (dynamic-extent cur))
+ (cond (dim (dotimes (i (pop dim)) (setf (car cur) i) (maset array x dim cx (cdr cur) ind)))
+ ((incf (cdr cx))
+ (when (apply 'array-in-bounds-p array ind)
+ (row-major-aset (apply 'aref array ind) (car cx) (cdr cx))))))
+
(defun adjust-array (array new-dimensions
- &rest r
&key element-type
initial-element
- initial-contents
+ (initial-contents nil initial-contents-supplied-p)
fill-pointer
displaced-to
- displaced-index-offset
- static
- &aux fill-pointer-spec
- )
- (declare (ignore
- initial-element
- initial-contents
- fill-pointer
- displaced-to
- displaced-index-offset
- static))
- (declare (:dynamic-extent r new-dimensions))
- (when (integerp new-dimensions)
- (setq new-dimensions (list new-dimensions)))
- (if (setq fill-pointer-spec (member :fill-pointer r))
- (unless (array-has-fill-pointer-p array)
- (error ":fill-pointer specified for array with no fill pointer"))
- (when (array-has-fill-pointer-p array)
- (push (fill-pointer array) r) (push :fill-pointer r)))
-
- (setq element-type (array-element-type array))
- (unless (eq element-type t) (push element-type r)
- (push :element-type r))
- (unless (member :static r)
- (push (staticp array) r) (push :static r))
- (let ((x (apply #'make-array new-dimensions :adjustable t r)))
- (cond ((or (null (cdr new-dimensions))
- (and (equal (cdr new-dimensions)
- (cdr (array-dimensions array)))
- (or (not (eq element-type 'bit))
- (eql 0 (the fixnum
- (mod
- (the fixnum (car (last new-dimensions)))
- char-size))))))
- (copy-array-portion array x
- 0 0
- (min (array-total-size x)
- (array-total-size array))))
- (t
- (do ((cursor (make-list (length new-dimensions)
- :initial-element 0)))
- (nil)
- (declare (:dynamic-extent cursor))
- (when (apply #'array-in-bounds-p array cursor)
- (aset-by-cursor x
- (apply #'aref array cursor)
- cursor))
- (when (increment-cursor cursor new-dimensions)
- (return nil)))))
+ (displaced-index-offset 0)
+ (static (staticp array))
+ &aux (fill-pointer (or fill-pointer (when (array-has-fill-pointer-p array) (fill-pointer array)))))
+
+ (declare (ignore element-type))
+
+ (let ((x (if initial-contents-supplied-p
+ (make-array new-dimensions
+ :adjustable t
+ :static static
+ :element-type (array-element-type array)
+ :fill-pointer fill-pointer
+ :initial-contents initial-contents
+ :displaced-to displaced-to
+ :displaced-index-offset displaced-index-offset)
+ (make-array new-dimensions
+ :adjustable t
+ :static static
+ :element-type (array-element-type array)
+ :fill-pointer fill-pointer
+ :initial-element initial-element
+ :displaced-to displaced-to
+ :displaced-index-offset displaced-index-offset))))
+
+ (unless (or displaced-to initial-contents-supplied-p)
+
+ (cond ((or (atom new-dimensions)
+ (null (cdr new-dimensions))
+ (when (equal (cdr new-dimensions) (cdr (array-dimensions array)))
+ (or (not (eq element-type 'bit))
+ (eql 0 (the fixnum (mod (the fixnum (car (last new-dimensions))) char-size))))))
+ (copy-array-portion array x 0 0 (min (array-total-size x) (array-total-size array))))
+ ((maset array x new-dimensions))))
(si:replace-array array x)
- (setf fill-pointer-spec (cadr fill-pointer-spec))
- (when fill-pointer-spec
- (cond ((eql t fill-pointer-spec)
- (setf (fill-pointer array) (array-total-size array)))
- ((typep fill-pointer-spec 'fixnum)
- (setf (fill-pointer array) fill-pointer-spec))
- (t (error "bad :fill-pointer arg: ~a" fill-pointer-spec))))
- array
- ))
+
+ (when fill-pointer
+ (setf (fill-pointer array) (if (eq fill-pointer t) (array-total-size array) fill-pointer)))
+ array))
+
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月09日 21:30:16 +0000

AltStyle によって変換されたページ (->オリジナル) /