aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2016-02-04 16:36:48 -0800
committerPaul Eggert2016-02-04 16:39:12 -0800
commit605f9019b47764d5b46544e525fa46b375951b35 (patch)
tree20a940e30762c0edd9fb16f51c46fd80b7da7e29
parent46dfdd831b817ef9e281350043bd4231f2dc5acc (diff)
downloademacs-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.
-rw-r--r--src/alloc.c37
-rw-r--r--src/ccl.c5
-rw-r--r--src/charset.c4
3 files changed, 17 insertions, 29 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)
3318DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0, 3318DEFUN ("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.
3320See also the function `vector'. */) 3320See 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
3339DEFUN ("vector", Fvector, Svector, 0, MANY, 0, 3335DEFUN ("vector", Fvector, Svector, 0, MANY, 0,
@@ -3342,12 +3338,9 @@ Any number of arguments, even zero arguments, are allowed.
3342usage: (vector &rest OBJECTS) */) 3338usage: (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.
3386usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INTERACTIVE-SPEC &rest ELEMENTS) */) 3379usage: (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;
diff --git a/src/ccl.c b/src/ccl.c
index 8cfd9b5c8ee..ef6cb9862b8 100644
--- a/src/ccl.c
+++ b/src/ccl.c
@@ -1908,8 +1908,6 @@ ccl_get_compiled_code (Lisp_Object ccl_prog, ptrdiff_t *idx)
1908bool 1908bool
1909setup_ccl_program (struct ccl_program *ccl, Lisp_Object ccl_prog) 1909setup_ccl_program (struct ccl_program *ccl, Lisp_Object ccl_prog)
1910{ 1910{
1911 int i;
1912
1913 if (! NILP (ccl_prog)) 1911 if (! NILP (ccl_prog))
1914 { 1912 {
1915 struct Lisp_Vector *vp; 1913 struct Lisp_Vector *vp;
@@ -1931,8 +1929,7 @@ setup_ccl_program (struct ccl_program *ccl, Lisp_Object ccl_prog)
1931 } 1929 }
1932 } 1930 }
1933 ccl->ic = CCL_HEADER_MAIN; 1931 ccl->ic = CCL_HEADER_MAIN;
1934 for (i = 0; i < 8; i++) 1932 memset (ccl->reg, 0, sizeof ccl->reg);
1935 ccl->reg[i] = 0;
1936 ccl->last_block = false; 1933 ccl->last_block = false;
1937 ccl->status = 0; 1934 ccl->status = 0;
1938 ccl->stack_idx = 0; 1935 ccl->stack_idx = 0;
diff --git a/src/charset.c b/src/charset.c
index 48e476813be..f911e9e5e0a 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -1050,8 +1050,8 @@ usage: (define-charset-internal ...) */)
1050 /* Here, we just copy the parent's fast_map. It's not accurate, 1050 /* Here, we just copy the parent's fast_map. It's not accurate,
1051 but at least it works for quickly detecting which character 1051 but at least it works for quickly detecting which character
1052 DOESN'T belong to this charset. */ 1052 DOESN'T belong to this charset. */
1053 for (i = 0; i < 190; i++) 1053 memcpy (charset.fast_map, parent_charset->fast_map,
1054 charset.fast_map[i] = parent_charset->fast_map[i]; 1054 sizeof charset.fast_map);
1055 1055
1056 /* We also copy these for parents. */ 1056 /* We also copy these for parents. */
1057 charset.min_char = parent_charset->min_char; 1057 charset.min_char = parent_charset->min_char;