diff options
| author | Paul Eggert | 2016-02-04 16:36:48 -0800 |
|---|---|---|
| committer | Paul Eggert | 2016-02-04 16:39:12 -0800 |
| commit | 605f9019b47764d5b46544e525fa46b375951b35 (patch) | |
| tree | 20a940e30762c0edd9fb16f51c46fd80b7da7e29 /src/alloc.c | |
| parent | 46dfdd831b817ef9e281350043bd4231f2dc5acc (diff) | |
| download | emacs-605f9019b47764d5b46544e525fa46b375951b35.tar.gz emacs-605f9019b47764d5b46544e525fa46b375951b35.zip | |
Prefer memcpy and memset to doing it by hand
* src/alloc.c (Fmake_vector):
* src/ccl.c (setup_ccl_program):
Use memset to clear array.
* src/alloc.c (Fvector, Fmake_byte_code):
* src/charset.c (Fdefine_charset_internal):
Use memcpy to copy array.
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/src/alloc.c b/src/alloc.c index ca86a84b06d..031c78c07ca 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -3318,22 +3318,18 @@ allocate_buffer (void) | |||
| 3318 | DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0, | 3318 | DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0, |
| 3319 | doc: /* Return a newly created vector of length LENGTH, with each element being INIT. | 3319 | doc: /* Return a newly created vector of length LENGTH, with each element being INIT. |
| 3320 | See also the function `vector'. */) | 3320 | See also the function `vector'. */) |
| 3321 | (register Lisp_Object length, Lisp_Object init) | 3321 | (Lisp_Object length, Lisp_Object init) |
| 3322 | { | 3322 | { |
| 3323 | Lisp_Object vector; | ||
| 3324 | register ptrdiff_t sizei; | ||
| 3325 | register ptrdiff_t i; | ||
| 3326 | register struct Lisp_Vector *p; | ||
| 3327 | |||
| 3328 | CHECK_NATNUM (length); | 3323 | CHECK_NATNUM (length); |
| 3329 | 3324 | ||
| 3330 | p = allocate_vector (XFASTINT (length)); | 3325 | struct Lisp_Vector *p = allocate_vector (XFASTINT (length)); |
| 3331 | sizei = XFASTINT (length); | 3326 | if (XLI (init) == 0) |
| 3332 | for (i = 0; i < sizei; i++) | 3327 | memset (p->contents, 0, XFASTINT (length) * sizeof p->contents[0]); |
| 3333 | p->contents[i] = init; | 3328 | else |
| 3329 | for (ptrdiff_t i = 0; i < XFASTINT (length); i++) | ||
| 3330 | p->contents[i] = init; | ||
| 3334 | 3331 | ||
| 3335 | XSETVECTOR (vector, p); | 3332 | return make_lisp_ptr (p, Lisp_Vectorlike); |
| 3336 | return vector; | ||
| 3337 | } | 3333 | } |
| 3338 | 3334 | ||
| 3339 | DEFUN ("vector", Fvector, Svector, 0, MANY, 0, | 3335 | DEFUN ("vector", Fvector, Svector, 0, MANY, 0, |
| @@ -3342,12 +3338,9 @@ Any number of arguments, even zero arguments, are allowed. | |||
| 3342 | usage: (vector &rest OBJECTS) */) | 3338 | usage: (vector &rest OBJECTS) */) |
| 3343 | (ptrdiff_t nargs, Lisp_Object *args) | 3339 | (ptrdiff_t nargs, Lisp_Object *args) |
| 3344 | { | 3340 | { |
| 3345 | ptrdiff_t i; | 3341 | Lisp_Object val = make_uninit_vector (nargs); |
| 3346 | register Lisp_Object val = make_uninit_vector (nargs); | 3342 | struct Lisp_Vector *p = XVECTOR (val); |
| 3347 | register struct Lisp_Vector *p = XVECTOR (val); | 3343 | memcpy (p->contents, args, nargs * sizeof *args); |
| 3348 | |||
| 3349 | for (i = 0; i < nargs; i++) | ||
| 3350 | p->contents[i] = args[i]; | ||
| 3351 | return val; | 3344 | return val; |
| 3352 | } | 3345 | } |
| 3353 | 3346 | ||
| @@ -3386,9 +3379,8 @@ stack before executing the byte-code. | |||
| 3386 | usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INTERACTIVE-SPEC &rest ELEMENTS) */) | 3379 | usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INTERACTIVE-SPEC &rest ELEMENTS) */) |
| 3387 | (ptrdiff_t nargs, Lisp_Object *args) | 3380 | (ptrdiff_t nargs, Lisp_Object *args) |
| 3388 | { | 3381 | { |
| 3389 | ptrdiff_t i; | 3382 | Lisp_Object val = make_uninit_vector (nargs); |
| 3390 | register Lisp_Object val = make_uninit_vector (nargs); | 3383 | struct Lisp_Vector *p = XVECTOR (val); |
| 3391 | register struct Lisp_Vector *p = XVECTOR (val); | ||
| 3392 | 3384 | ||
| 3393 | /* We used to purecopy everything here, if purify-flag was set. This worked | 3385 | /* We used to purecopy everything here, if purify-flag was set. This worked |
| 3394 | OK for Emacs-23, but with Emacs-24's lexical binding code, it can be | 3386 | OK for Emacs-23, but with Emacs-24's lexical binding code, it can be |
| @@ -3398,8 +3390,7 @@ usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INT | |||
| 3398 | just wasteful and other times plainly wrong (e.g. those free vars may want | 3390 | just wasteful and other times plainly wrong (e.g. those free vars may want |
| 3399 | to be setcar'd). */ | 3391 | to be setcar'd). */ |
| 3400 | 3392 | ||
| 3401 | for (i = 0; i < nargs; i++) | 3393 | memcpy (p->contents, args, nargs * sizeof *args); |
| 3402 | p->contents[i] = args[i]; | ||
| 3403 | make_byte_code (p); | 3394 | make_byte_code (p); |
| 3404 | XSETCOMPILED (val, p); | 3395 | XSETCOMPILED (val, p); |
| 3405 | return val; | 3396 | return val; |