Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
alexandria
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alexander Fedorov
alexandria
Commits
75f9136a
Commit
75f9136a
authored
13 years ago
by
Svante Carl v. Erichsen
Committed by
Nikodemus Siivola
13 years ago
Browse files
Options
Downloads
Patches
Plain Diff
improved COPY-ARRAY
No need to depend on the vagaries of ADJUST-ARRAY.
parent
cd158549
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arrays.lisp
+14
-16
14 additions, 16 deletions
arrays.lisp
tests.lisp
+18
-0
18 additions, 0 deletions
tests.lisp
with
32 additions
and
16 deletions
arrays.lisp
+
14
−
16
View file @
75f9136a
(
in-package
:alexandria
)
(
defun
copy-array
(
array
&key
(
element-type
(
array-element-type
array
))
(
fill-pointer
(
and
(
array-has-fill-pointer-p
array
)
(
fill-pointer
array
)))
(
adjustable
(
adjustable-array-p
array
)))
(
defun
copy-array
(
array
&key
(
element-type
(
array-element-type
array
))
(
fill-pointer
(
and
(
array-has-fill-pointer-p
array
)
(
fill-pointer
array
)))
(
adjustable
(
adjustable-array-p
array
)))
"Returns an undisplaced copy of ARRAY, with same fill-pointer and
adjustability (if any) as the original, unless overridden by the keyword
arguments. Performance depends on efficiency of general ADJUST-ARRAY in the
host lisp -- for most cases a special purpose copying function is likely to
perform better."
(
let
((
dims
(
array-dimensions
array
)))
;; Dictionary entry for ADJUST-ARRAY requires adjusting a
;; displaced array to a non-displaced one to make a copy.
(
adjust-array
(
make-array
dims
:element-type
element-type
:fill-pointer
fill-pointer
:adjustable
adjustable
:displaced-to
array
)
dims
)))
arguments."
(
let*
((
dimensions
(
array-dimensions
array
))
(
new-array
(
make-array
dimensions
:element-type
element-type
:adjustable
adjustable
:fill-pointer
fill-pointer
)))
(
dotimes
(
i
(
array-total-size
array
))
(
setf
(
row-major-aref
new-array
i
)
(
row-major-aref
array
i
)))
new-array
))
This diff is collapsed.
Click to expand it.
tests.lisp
+
18
−
0
View file @
75f9136a
...
...
@@ -29,6 +29,24 @@
(
eql
(
fill-pointer
orig
)
(
fill-pointer
copy
)))))
nil
t
t
t
)
(
deftest
copy-array.3
(
let*
((
orig
(
vector
1
2
3
))
(
copy
(
copy-array
orig
)))
(
typep
copy
'simple-array
))
t
)
(
deftest
copy-array.4
(
let
((
orig
(
make-array
21
:adjustable
t
:fill-pointer
0
)))
(
dotimes
(
n
42
)
(
vector-push-extend
n
orig
))
(
let
((
copy
(
copy-array
orig
:adjustable
nil
:fill-pointer
nil
)))
(
typep
copy
'simple-array
)))
t
)
(
deftest
array-index.1
(
typep
0
'array-index
)
t
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment