aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorDmitry Antipov2013-10-07 11:15:37 +0400
committerDmitry Antipov2013-10-07 11:15:37 +0400
commit3c439e0a8410d713488b16af5842ad8ef0cddb04 (patch)
tree4f2844dcb18cbf5050be459681857ded921bc7df /src/alloc.c
parent55ca2c0df0b7bdc2c425c17cc74dfc08a9ad236c (diff)
downloademacs-3c439e0a8410d713488b16af5842ad8ef0cddb04.tar.gz
emacs-3c439e0a8410d713488b16af5842ad8ef0cddb04.zip
* alloc.c (Fmake_string): For ASCII char initializer, prefer
memset to explicit loop. Otherwise copy largest possible chunk from initialized to uninitialized part, thus allowing the longer memcpy runs and reducing the number of loop iterations.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 0a7fda6815c..56a9763db15 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -1973,7 +1973,6 @@ INIT must be an integer that represents a character. */)
1973 (Lisp_Object length, Lisp_Object init) 1973 (Lisp_Object length, Lisp_Object init)
1974{ 1974{
1975 register Lisp_Object val; 1975 register Lisp_Object val;
1976 register unsigned char *p, *end;
1977 int c; 1976 int c;
1978 EMACS_INT nbytes; 1977 EMACS_INT nbytes;
1979 1978
@@ -1985,31 +1984,36 @@ INIT must be an integer that represents a character. */)
1985 { 1984 {
1986 nbytes = XINT (length); 1985 nbytes = XINT (length);
1987 val = make_uninit_string (nbytes); 1986 val = make_uninit_string (nbytes);
1988 p = SDATA (val); 1987 memset (SDATA (val), c, nbytes);
1989 end = p + SCHARS (val); 1988 SDATA (val)[nbytes] = 0;
1990 while (p != end)
1991 *p++ = c;
1992 } 1989 }
1993 else 1990 else
1994 { 1991 {
1995 unsigned char str[MAX_MULTIBYTE_LENGTH]; 1992 unsigned char str[MAX_MULTIBYTE_LENGTH];
1996 int len = CHAR_STRING (c, str); 1993 int len = CHAR_STRING (c, str);
1997 EMACS_INT string_len = XINT (length); 1994 EMACS_INT string_len = XINT (length);
1995 unsigned char *p, *beg, *end;
1998 1996
1999 if (string_len > STRING_BYTES_MAX / len) 1997 if (string_len > STRING_BYTES_MAX / len)
2000 string_overflow (); 1998 string_overflow ();
2001 nbytes = len * string_len; 1999 nbytes = len * string_len;
2002 val = make_uninit_multibyte_string (string_len, nbytes); 2000 val = make_uninit_multibyte_string (string_len, nbytes);
2003 p = SDATA (val); 2001 for (beg = SDATA (val), p = beg, end = beg + nbytes; p < end; p += len)
2004 end = p + nbytes;
2005 while (p != end)
2006 { 2002 {
2007 memcpy (p, str, len); 2003 /* First time we just copy `str' to the data of `val'. */
2008 p += len; 2004 if (p == beg)
2005 memcpy (p, str, len);
2006 else
2007 {
2008 /* Next time we copy largest possible chunk from
2009 initialized to uninitialized part of `val'. */
2010 len = min (p - beg, end - p);
2011 memcpy (p, beg, len);
2012 }
2009 } 2013 }
2014 *p = 0;
2010 } 2015 }
2011 2016
2012 *p = 0;
2013 return val; 2017 return val;
2014} 2018}
2015 2019