emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r108967: Use make_formatted_string to


From: Dmitry Antipov
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r108967: Use make_formatted_string to avoid double length calculation.
Date: Mon, 09 Jul 2012 16:02:27 +0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 108967
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Mon 2012-07-09 16:02:27 +0400
message:
  Use make_formatted_string to avoid double length calculation.
  * lisp.h (make_formatted_string): New prototype.
  * alloc.c (make_formatted_string): New function.
  * buffer.c (Fgenerate_new_buffer_name): Use it.
  * dbus.c (syms_of_dbusbind): Likewise.
  * editfns.c (Fcurrent_time_zone): Likewise.
  * filelock.c (get_boot_time): Likewise.
  * frame.c (make_terminal_frame, set_term_frame_name)
  (x_report_frame_params): Likewise.
  * image.c (gs_load): Likewise.
  * minibuf.c (get_minibuffer): Likewise.
  * msdos.c (dos_set_window_size): Likewise.
  * process.c (make_process): Likewise.
  * xdisp.c (ensure_echo_area_buffers): Likewise.
  * xsettings.c (apply_xft_settings): Likewise.
modified:
  src/ChangeLog
  src/alloc.c
  src/buffer.c
  src/dbusbind.c
  src/editfns.c
  src/filelock.c
  src/frame.c
  src/image.c
  src/lisp.h
  src/minibuf.c
  src/msdos.c
  src/process.c
  src/xdisp.c
  src/xsettings.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2012-07-09 07:07:24 +0000
+++ b/src/ChangeLog     2012-07-09 12:02:27 +0000
@@ -1,3 +1,21 @@
+2012-07-09  Dmitry Antipov  <address@hidden>
+
+       Use make_formatted_string to avoid double length calculation.
+       * lisp.h (make_formatted_string): New prototype.
+       * alloc.c (make_formatted_string): New function.
+       * buffer.c (Fgenerate_new_buffer_name): Use it.
+       * dbus.c (syms_of_dbusbind): Likewise.
+       * editfns.c (Fcurrent_time_zone): Likewise.
+       * filelock.c (get_boot_time): Likewise.
+       * frame.c (make_terminal_frame, set_term_frame_name)
+       (x_report_frame_params): Likewise.
+       * image.c (gs_load): Likewise.
+       * minibuf.c (get_minibuffer): Likewise.
+       * msdos.c (dos_set_window_size): Likewise.
+       * process.c (make_process): Likewise.
+       * xdisp.c (ensure_echo_area_buffers): Likewise.
+       * xsettings.c (apply_xft_settings): Likewise.
+
 2012-07-09  Glenn Morris  <address@hidden>
 
        Stop ns builds polluting the environment with EMACSDATA, EMACSDOC.

=== modified file 'src/alloc.c'
--- a/src/alloc.c       2012-07-06 05:07:44 +0000
+++ b/src/alloc.c       2012-07-09 12:02:27 +0000
@@ -2517,6 +2517,20 @@
   return string;
 }
 
+/* Print arguments to BUF according to a FORMAT, then return
+   a Lisp_String initialized with the data from BUF.  */
+
+Lisp_Object
+make_formatted_string (char *buf, const char *format, ...)
+{
+  va_list ap;
+  ptrdiff_t length;
+
+  va_start (ap, format);
+  length = vsprintf (buf, format, ap);
+  va_end (ap);
+  return make_string (buf, length);
+}
 
 
 /***********************************************************************

=== modified file 'src/buffer.c'
--- a/src/buffer.c      2012-07-06 07:34:37 +0000
+++ b/src/buffer.c      2012-07-09 12:02:27 +0000
@@ -861,8 +861,9 @@
   if (!strncmp (SSDATA (name), " ", 1)) /* see bug#1229 */
     {
       /* Note fileio.c:make_temp_name does random differently.  */
-      sprintf (number, "-%"pI"d", XFASTINT (Frandom (make_number (999999))));
-      tem2 = concat2 (name, build_string (number));
+      tem2 = concat2 (name, make_formatted_string
+                     (number, "-%"pI"d", 
+                      XFASTINT (Frandom (make_number (999999)))));
       tem = Fget_buffer (tem2);
       if (NILP (tem))
        return tem2;
@@ -873,8 +874,8 @@
   count = 1;
   while (1)
     {
-      sprintf (number, "<%"pD"d>", ++count);
-      gentemp = concat2 (tem2, build_string (number));
+      gentemp = concat2 (tem2, make_formatted_string
+                        (number, "<%"pD"d>", ++count));
       tem = Fstring_equal (gentemp, ignore);
       if (!NILP (tem))
        return gentemp;

=== modified file 'src/dbusbind.c'
--- a/src/dbusbind.c    2012-06-09 11:13:30 +0000
+++ b/src/dbusbind.c    2012-07-09 12:02:27 +0000
@@ -1757,8 +1757,8 @@
     int major, minor, micro;
     char s[sizeof ".." + 3 * INT_STRLEN_BOUND (int)];
     dbus_get_version (&major, &minor, &micro);
-    sprintf (s, "%d.%d.%d", major, minor, micro);
-    Vdbus_runtime_version = build_string (s);
+    Vdbus_runtime_version
+      = make_formatted_string (s, "%d.%d.%d", major, minor, micro);
 #else
     Vdbus_runtime_version = Qnil;
 #endif

=== modified file 'src/editfns.c'
--- a/src/editfns.c     2012-07-07 01:57:42 +0000
+++ b/src/editfns.c     2012-07-09 12:02:27 +0000
@@ -2082,8 +2082,9 @@
          int m = offset / 60;
          int am = offset < 0 ? - m : m;
          char buf[sizeof "+00" + INT_STRLEN_BOUND (int)];
-         sprintf (buf, "%c%02d%02d", (offset < 0 ? '-' : '+'), am/60, am%60);
-         zone_name = build_string (buf);
+         zone_name = make_formatted_string (buf, "%c%02d%02d", 
+                                            (offset < 0 ? '-' : '+'),
+                                            am / 60, am % 60);
        }
     }
 

=== modified file 'src/filelock.c'
--- a/src/filelock.c    2012-07-05 18:35:48 +0000
+++ b/src/filelock.c    2012-07-09 12:02:27 +0000
@@ -174,14 +174,14 @@
 
       filename = Qnil;
 
-      sprintf (cmd_string, "%s.%d", WTMP_FILE, counter);
-      tempname = build_string (cmd_string);
+      tempname = make_formatted_string
+       (cmd_string, "%s.%d", WTMP_FILE, counter);
       if (! NILP (Ffile_exists_p (tempname)))
        filename = tempname;
       else
        {
-         sprintf (cmd_string, "%s.%d.gz", WTMP_FILE, counter);
-         tempname = build_string (cmd_string);
+         tempname = make_formatted_string (cmd_string, "%s.%d.gz",
+                                           WTMP_FILE, counter);
          if (! NILP (Ffile_exists_p (tempname)))
            {
              Lisp_Object args[6];

=== modified file 'src/frame.c'
--- a/src/frame.c       2012-07-07 21:39:23 +0000
+++ b/src/frame.c       2012-07-09 12:02:27 +0000
@@ -518,9 +518,7 @@
   XSETFRAME (frame, f);
   Vframe_list = Fcons (frame, Vframe_list);
 
-  tty_frame_count++;
-  sprintf (name, "F%"pMd, tty_frame_count);
-  f->name = build_string (name);
+  f->name = make_formatted_string (name, "F%"pMd, ++tty_frame_count);
 
   f->visible = 1;              /* FRAME_SET_VISIBLE wd set frame_garbaged. */
   f->async_visible = 1;                /* Don't let visible be cleared later. 
*/
@@ -2028,9 +2026,7 @@
                            SBYTES (f->name)))
        return;
 
-      tty_frame_count++;
-      sprintf (namebuf, "F%"pMd, tty_frame_count);
-      name = build_string (namebuf);
+      name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
     }
   else
     {
@@ -3049,20 +3045,16 @@
      actually a pointer.  Explicit casting avoids compiler
      warnings.  */
   w = (unsigned long) FRAME_X_WINDOW (f);
-  sprintf (buf, "%lu", w);
   store_in_alist (alistptr, Qwindow_id,
-                 build_string (buf));
+                 make_formatted_string (buf, "%lu", w));
 #ifdef HAVE_X_WINDOWS
 #ifdef USE_X_TOOLKIT
   /* Tooltip frame may not have this widget.  */
   if (FRAME_X_OUTPUT (f)->widget)
 #endif
-    {
-      w = (unsigned long) FRAME_OUTER_WINDOW (f);
-      sprintf (buf, "%lu", w);
-    }
+    w = (unsigned long) FRAME_OUTER_WINDOW (f);
   store_in_alist (alistptr, Qouter_window_id,
-                 build_string (buf));
+                 make_formatted_string (buf, "%lu", w));
 #endif
   store_in_alist (alistptr, Qicon_name, f->icon_name);
   FRAME_SAMPLE_VISIBILITY (f);

=== modified file 'src/image.c'
--- a/src/image.c       2012-07-07 19:23:41 +0000
+++ b/src/image.c       2012-07-09 12:02:27 +0000
@@ -8549,13 +8549,13 @@
      don't either.  Let the Lisp loader use `unwind-protect' instead.  */
   printnum1 = FRAME_X_WINDOW (f);
   printnum2 = img->pixmap;
-  sprintf (buffer, "%"pMu" %"pMu, printnum1, printnum2);
-  window_and_pixmap_id = build_string (buffer);
+  window_and_pixmap_id 
+    = make_formatted_string (buffer, "%"pMu" %"pMu, printnum1, printnum2);
 
   printnum1 = FRAME_FOREGROUND_PIXEL (f);
   printnum2 = FRAME_BACKGROUND_PIXEL (f);
-  sprintf (buffer, "%"pMu" %"pMu, printnum1, printnum2);
-  pixel_colors = build_string (buffer);
+  pixel_colors
+    = make_formatted_string (buffer, "%"pMu" %"pMu, printnum1, printnum2);
 
   XSETFRAME (frame, f);
   loader = image_spec_value (img->spec, QCloader, NULL);

=== modified file 'src/lisp.h'
--- a/src/lisp.h        2012-07-07 21:39:23 +0000
+++ b/src/lisp.h        2012-07-09 12:02:27 +0000
@@ -2611,6 +2611,7 @@
 extern Lisp_Object allocate_misc (void);
 extern _Noreturn void string_overflow (void);
 extern Lisp_Object make_string (const char *, ptrdiff_t);
+extern Lisp_Object make_formatted_string (char *, const char *, ...);
 extern Lisp_Object make_unibyte_string (const char *, ptrdiff_t);
 extern Lisp_Object make_multibyte_string (const char *, ptrdiff_t, ptrdiff_t);
 extern Lisp_Object make_event_array (int, Lisp_Object *);

=== modified file 'src/minibuf.c'
--- a/src/minibuf.c     2012-07-06 04:42:30 +0000
+++ b/src/minibuf.c     2012-07-09 12:02:27 +0000
@@ -792,8 +792,8 @@
   buf = Fcar (tail);
   if (NILP (buf) || NILP (BVAR (XBUFFER (buf), name)))
     {
-      sprintf (name, " *Minibuf-%"pI"d*", depth);
-      buf = Fget_buffer_create (build_string (name));
+      buf = Fget_buffer_create
+       (make_formatted_string (name, " *Minibuf-%"pI"d*", depth));
 
       /* Although the buffer's name starts with a space, undo should be
         enabled in it.  */

=== modified file 'src/msdos.c'
--- a/src/msdos.c       2012-07-05 06:32:41 +0000
+++ b/src/msdos.c       2012-07-09 12:02:27 +0000
@@ -520,8 +520,10 @@
 
   /* If the user specified a special video mode for these dimensions,
      use that mode.  */
-  sprintf (video_name, "screen-dimensions-%dx%d", *rows, *cols);
-  video_mode = Fsymbol_value (Fintern_soft (build_string (video_name), Qnil));
+  video_mode 
+    = Fsymbol_value (Fintern_soft (make_formatted_string 
+                                  (video_name, "screen-dimensions-%dx%d",
+                                   *rows, *cols), Qnil));
 
   if (INTEGERP (video_mode)
       && (video_mode_value = XINT (video_mode)) > 0)

=== modified file 'src/process.c'
--- a/src/process.c     2012-07-06 16:57:32 +0000
+++ b/src/process.c     2012-07-09 12:02:27 +0000
@@ -645,8 +645,7 @@
     {
       tem = Fget_process (name1);
       if (NILP (tem)) break;
-      sprintf (suffix, "<%"pMd">", i);
-      name1 = concat2 (name, build_string (suffix));
+      name1 = concat2 (name, make_formatted_string (suffix, "<%"pMd">", i));
     }
   name = name1;
   p->name = name;

=== modified file 'src/xdisp.c'
--- a/src/xdisp.c       2012-07-08 16:38:43 +0000
+++ b/src/xdisp.c       2012-07-09 12:02:27 +0000
@@ -9866,8 +9866,8 @@
        int j;
 
        old_buffer = echo_buffer[i];
-       sprintf (name, " *Echo Area %d*", i);
-       echo_buffer[i] = Fget_buffer_create (build_string (name));
+       echo_buffer[i] = Fget_buffer_create
+         (make_formatted_string (name, " *Echo Area %d*", i));
        BVAR (XBUFFER (echo_buffer[i]), truncate_lines) = Qnil;
        /* to force word wrap in echo area -
           it was decided to postpone this*/

=== modified file 'src/xsettings.c'
--- a/src/xsettings.c   2012-06-27 15:46:48 +0000
+++ b/src/xsettings.c   2012-07-09 12:02:27 +0000
@@ -711,10 +711,12 @@
       if (send_event_p)
         store_config_changed_event (Qfont_render,
                                     XCAR (dpyinfo->name_list_element));
-      sprintf (buf, format, oldsettings.aa, oldsettings.hinting,
-              oldsettings.rgba, oldsettings.lcdfilter,
-              oldsettings.hintstyle, oldsettings.dpi);
-      Vxft_settings = build_string (buf);
+      Vxft_settings 
+       = make_formatted_string (buf, format,
+                                oldsettings.aa, oldsettings.hinting,
+                                oldsettings.rgba, oldsettings.lcdfilter,
+                                oldsettings.hintstyle, oldsettings.dpi);
+      
     }
   else
     FcPatternDestroy (pat);


reply via email to

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