From: Paul Eggert Date: Fri, 5 Feb 2016 00:36:48 +0000 (-0800) Subject: Prefer memcpy and memset to doing it by hand X-Git-Tag: emacs-26.0.90~2737 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=605f9019b47764d5b46544e525fa46b375951b35;p=emacs.git 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. --- 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) DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0, doc: /* Return a newly created vector of length LENGTH, with each element being INIT. See also the function `vector'. */) - (register Lisp_Object length, Lisp_Object init) + (Lisp_Object length, Lisp_Object init) { - Lisp_Object vector; - register ptrdiff_t sizei; - register ptrdiff_t i; - register struct Lisp_Vector *p; - CHECK_NATNUM (length); - p = allocate_vector (XFASTINT (length)); - sizei = XFASTINT (length); - for (i = 0; i < sizei; i++) - p->contents[i] = init; + struct Lisp_Vector *p = allocate_vector (XFASTINT (length)); + if (XLI (init) == 0) + memset (p->contents, 0, XFASTINT (length) * sizeof p->contents[0]); + else + for (ptrdiff_t i = 0; i < XFASTINT (length); i++) + p->contents[i] = init; - XSETVECTOR (vector, p); - return vector; + return make_lisp_ptr (p, Lisp_Vectorlike); } DEFUN ("vector", Fvector, Svector, 0, MANY, 0, @@ -3342,12 +3338,9 @@ Any number of arguments, even zero arguments, are allowed. usage: (vector &rest OBJECTS) */) (ptrdiff_t nargs, Lisp_Object *args) { - ptrdiff_t i; - register Lisp_Object val = make_uninit_vector (nargs); - register struct Lisp_Vector *p = XVECTOR (val); - - for (i = 0; i < nargs; i++) - p->contents[i] = args[i]; + Lisp_Object val = make_uninit_vector (nargs); + struct Lisp_Vector *p = XVECTOR (val); + memcpy (p->contents, args, nargs * sizeof *args); return val; } @@ -3386,9 +3379,8 @@ stack before executing the byte-code. usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INTERACTIVE-SPEC &rest ELEMENTS) */) (ptrdiff_t nargs, Lisp_Object *args) { - ptrdiff_t i; - register Lisp_Object val = make_uninit_vector (nargs); - register struct Lisp_Vector *p = XVECTOR (val); + Lisp_Object val = make_uninit_vector (nargs); + struct Lisp_Vector *p = XVECTOR (val); /* We used to purecopy everything here, if purify-flag was set. This worked 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 just wasteful and other times plainly wrong (e.g. those free vars may want to be setcar'd). */ - for (i = 0; i < nargs; i++) - p->contents[i] = args[i]; + memcpy (p->contents, args, nargs * sizeof *args); make_byte_code (p); XSETCOMPILED (val, p); 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) bool setup_ccl_program (struct ccl_program *ccl, Lisp_Object ccl_prog) { - int i; - if (! NILP (ccl_prog)) { struct Lisp_Vector *vp; @@ -1931,8 +1929,7 @@ setup_ccl_program (struct ccl_program *ccl, Lisp_Object ccl_prog) } } ccl->ic = CCL_HEADER_MAIN; - for (i = 0; i < 8; i++) - ccl->reg[i] = 0; + memset (ccl->reg, 0, sizeof ccl->reg); ccl->last_block = false; ccl->status = 0; 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 ...) */) /* Here, we just copy the parent's fast_map. It's not accurate, but at least it works for quickly detecting which character DOESN'T belong to this charset. */ - for (i = 0; i < 190; i++) - charset.fast_map[i] = parent_charset->fast_map[i]; + memcpy (charset.fast_map, parent_charset->fast_map, + sizeof charset.fast_map); /* We also copy these for parents. */ charset.min_char = parent_charset->min_char;