emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r114551: * alloc.c (Fmake_string): For ASCII char in


From: Dmitry Antipov
Subject: [Emacs-diffs] trunk r114551: * alloc.c (Fmake_string): For ASCII char initializer, prefer
Date: Mon, 07 Oct 2013 07:16:40 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 114551
revision-id: address@hidden
parent: address@hidden
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Mon 2013-10-07 11:15:37 +0400
message:
  * 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.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/alloc.c                    alloc.c-20091113204419-o5vbwnq5f7feedwu-252
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-10-06 15:59:11 +0000
+++ b/src/ChangeLog     2013-10-07 07:15:37 +0000
@@ -1,3 +1,10 @@
+2013-10-07  Dmitry Antipov  <address@hidden>
+
+       * 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  <address@hidden>
 
        * nsterm.m (ns_update_begin): If native fullscreen and no toolbar,

=== modified file 'src/alloc.c'
--- a/src/alloc.c       2013-10-03 16:16:31 +0000
+++ b/src/alloc.c       2013-10-07 07:15:37 +0000
@@ -1973,7 +1973,6 @@
   (Lisp_Object length, Lisp_Object init)
 {
   register Lisp_Object val;
-  register unsigned char *p, *end;
   int c;
   EMACS_INT nbytes;
 
@@ -1985,31 +1984,36 @@
     {
       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;
 }
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]