]> git.eshelyaron.com Git - emacs.git/commitdiff
* alloc.c (Fmake_string): For ASCII char initializer, prefer
authorDmitry Antipov <dmantipov@yandex.ru>
Mon, 7 Oct 2013 07:15:37 +0000 (11:15 +0400)
committerDmitry Antipov <dmantipov@yandex.ru>
Mon, 7 Oct 2013 07:15:37 +0000 (11:15 +0400)
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.

src/ChangeLog
src/alloc.c

index 07af64ab1a1175a0fc0b149b8239937cdb25f0eb..4be64c13993c7734f971208bc92266f78027ef3d 100644 (file)
@@ -1,3 +1,10 @@
+2013-10-07  Dmitry Antipov  <dmantipov@yandex.ru>
+
+       * 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.
+
 2013-10-06  Jan Djärv  <jan.h.d@swipnet.se>
 
        * nsterm.m (ns_update_begin): If native fullscreen and no toolbar,
index 0a7fda6815cc4141aa283df674d272ffb5bbbbc8..56a9763db153b3f9878f99383edbd7804d91e143 100644 (file)
@@ -1973,7 +1973,6 @@ INIT must be an integer that represents a character.  */)
   (Lisp_Object length, Lisp_Object init)
 {
   register Lisp_Object val;
-  register unsigned char *p, *end;
   int c;
   EMACS_INT nbytes;
 
@@ -1985,31 +1984,36 @@ INIT must be an integer that represents a character.  */)
     {
       nbytes = XINT (length);
       val = make_uninit_string (nbytes);
-      p = SDATA (val);
-      end = p + SCHARS (val);
-      while (p != end)
-       *p++ = c;
+      memset (SDATA (val), c, nbytes);
+      SDATA (val)[nbytes] = 0;
     }
   else
     {
       unsigned char str[MAX_MULTIBYTE_LENGTH];
       int len = CHAR_STRING (c, str);
       EMACS_INT string_len = XINT (length);
+      unsigned char *p, *beg, *end;
 
       if (string_len > STRING_BYTES_MAX / len)
        string_overflow ();
       nbytes = len * string_len;
       val = make_uninit_multibyte_string (string_len, nbytes);
-      p = SDATA (val);
-      end = p + nbytes;
-      while (p != end)
+      for (beg = SDATA (val), p = beg, end = beg + nbytes; p < end; p += len)
        {
-         memcpy (p, str, len);
-         p += len;
+         /* First time we just copy `str' to the data of `val'.  */
+         if (p == beg)
+           memcpy (p, str, len);
+         else
+           {
+             /* Next time we copy largest possible chunk from
+                initialized to uninitialized part of `val'.  */
+             len = min (p - beg, end - p);
+             memcpy (p, beg, len);
+           }
        }
+      *p = 0;
     }
 
-  *p = 0;
   return val;
 }