diff options
| author | Dmitry Antipov | 2012-07-09 16:02:27 +0400 |
|---|---|---|
| committer | Dmitry Antipov | 2012-07-09 16:02:27 +0400 |
| commit | a8290ec31c89dfdec85fc9d46000c66c0caa1697 (patch) | |
| tree | a1fcee6481bc8ef358abdeec12a15fcfd9c53649 /src | |
| parent | 27505cf5e4d61283be5368cfd200c942dded0c79 (diff) | |
| download | emacs-a8290ec31c89dfdec85fc9d46000c66c0caa1697.tar.gz emacs-a8290ec31c89dfdec85fc9d46000c66c0caa1697.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 18 | ||||
| -rw-r--r-- | src/alloc.c | 14 | ||||
| -rw-r--r-- | src/buffer.c | 9 | ||||
| -rw-r--r-- | src/dbusbind.c | 4 | ||||
| -rw-r--r-- | src/editfns.c | 5 | ||||
| -rw-r--r-- | src/filelock.c | 8 | ||||
| -rw-r--r-- | src/frame.c | 18 | ||||
| -rw-r--r-- | src/image.c | 8 | ||||
| -rw-r--r-- | src/lisp.h | 1 | ||||
| -rw-r--r-- | src/minibuf.c | 4 | ||||
| -rw-r--r-- | src/msdos.c | 6 | ||||
| -rw-r--r-- | src/process.c | 3 | ||||
| -rw-r--r-- | src/xdisp.c | 4 | ||||
| -rw-r--r-- | src/xsettings.c | 10 |
14 files changed, 71 insertions, 41 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 1aa5f7df5c3..4e69496fadd 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,21 @@ | |||
| 1 | 2012-07-09 Dmitry Antipov <dmantipov@yandex.ru> | ||
| 2 | |||
| 3 | Use make_formatted_string to avoid double length calculation. | ||
| 4 | * lisp.h (make_formatted_string): New prototype. | ||
| 5 | * alloc.c (make_formatted_string): New function. | ||
| 6 | * buffer.c (Fgenerate_new_buffer_name): Use it. | ||
| 7 | * dbus.c (syms_of_dbusbind): Likewise. | ||
| 8 | * editfns.c (Fcurrent_time_zone): Likewise. | ||
| 9 | * filelock.c (get_boot_time): Likewise. | ||
| 10 | * frame.c (make_terminal_frame, set_term_frame_name) | ||
| 11 | (x_report_frame_params): Likewise. | ||
| 12 | * image.c (gs_load): Likewise. | ||
| 13 | * minibuf.c (get_minibuffer): Likewise. | ||
| 14 | * msdos.c (dos_set_window_size): Likewise. | ||
| 15 | * process.c (make_process): Likewise. | ||
| 16 | * xdisp.c (ensure_echo_area_buffers): Likewise. | ||
| 17 | * xsettings.c (apply_xft_settings): Likewise. | ||
| 18 | |||
| 1 | 2012-07-09 Glenn Morris <rgm@gnu.org> | 19 | 2012-07-09 Glenn Morris <rgm@gnu.org> |
| 2 | 20 | ||
| 3 | Stop ns builds polluting the environment with EMACSDATA, EMACSDOC. | 21 | Stop ns builds polluting the environment with EMACSDATA, EMACSDOC. |
diff --git a/src/alloc.c b/src/alloc.c index 88f96c41a15..739ec40c45c 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -2517,6 +2517,20 @@ make_uninit_multibyte_string (EMACS_INT nchars, EMACS_INT nbytes) | |||
| 2517 | return string; | 2517 | return string; |
| 2518 | } | 2518 | } |
| 2519 | 2519 | ||
| 2520 | /* Print arguments to BUF according to a FORMAT, then return | ||
| 2521 | a Lisp_String initialized with the data from BUF. */ | ||
| 2522 | |||
| 2523 | Lisp_Object | ||
| 2524 | make_formatted_string (char *buf, const char *format, ...) | ||
| 2525 | { | ||
| 2526 | va_list ap; | ||
| 2527 | ptrdiff_t length; | ||
| 2528 | |||
| 2529 | va_start (ap, format); | ||
| 2530 | length = vsprintf (buf, format, ap); | ||
| 2531 | va_end (ap); | ||
| 2532 | return make_string (buf, length); | ||
| 2533 | } | ||
| 2520 | 2534 | ||
| 2521 | 2535 | ||
| 2522 | /*********************************************************************** | 2536 | /*********************************************************************** |
diff --git a/src/buffer.c b/src/buffer.c index a40270c945c..28cede3916c 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -861,8 +861,9 @@ is first appended to NAME, to speed up finding a non-existent buffer. */) | |||
| 861 | if (!strncmp (SSDATA (name), " ", 1)) /* see bug#1229 */ | 861 | if (!strncmp (SSDATA (name), " ", 1)) /* see bug#1229 */ |
| 862 | { | 862 | { |
| 863 | /* Note fileio.c:make_temp_name does random differently. */ | 863 | /* Note fileio.c:make_temp_name does random differently. */ |
| 864 | sprintf (number, "-%"pI"d", XFASTINT (Frandom (make_number (999999)))); | 864 | tem2 = concat2 (name, make_formatted_string |
| 865 | tem2 = concat2 (name, build_string (number)); | 865 | (number, "-%"pI"d", |
| 866 | XFASTINT (Frandom (make_number (999999))))); | ||
| 866 | tem = Fget_buffer (tem2); | 867 | tem = Fget_buffer (tem2); |
| 867 | if (NILP (tem)) | 868 | if (NILP (tem)) |
| 868 | return tem2; | 869 | return tem2; |
| @@ -873,8 +874,8 @@ is first appended to NAME, to speed up finding a non-existent buffer. */) | |||
| 873 | count = 1; | 874 | count = 1; |
| 874 | while (1) | 875 | while (1) |
| 875 | { | 876 | { |
| 876 | sprintf (number, "<%"pD"d>", ++count); | 877 | gentemp = concat2 (tem2, make_formatted_string |
| 877 | gentemp = concat2 (tem2, build_string (number)); | 878 | (number, "<%"pD"d>", ++count)); |
| 878 | tem = Fstring_equal (gentemp, ignore); | 879 | tem = Fstring_equal (gentemp, ignore); |
| 879 | if (!NILP (tem)) | 880 | if (!NILP (tem)) |
| 880 | return gentemp; | 881 | return gentemp; |
diff --git a/src/dbusbind.c b/src/dbusbind.c index d80bb21cd59..203a25c151a 100644 --- a/src/dbusbind.c +++ b/src/dbusbind.c | |||
| @@ -1757,8 +1757,8 @@ syms_of_dbusbind (void) | |||
| 1757 | int major, minor, micro; | 1757 | int major, minor, micro; |
| 1758 | char s[sizeof ".." + 3 * INT_STRLEN_BOUND (int)]; | 1758 | char s[sizeof ".." + 3 * INT_STRLEN_BOUND (int)]; |
| 1759 | dbus_get_version (&major, &minor, µ); | 1759 | dbus_get_version (&major, &minor, µ); |
| 1760 | sprintf (s, "%d.%d.%d", major, minor, micro); | 1760 | Vdbus_runtime_version |
| 1761 | Vdbus_runtime_version = build_string (s); | 1761 | = make_formatted_string (s, "%d.%d.%d", major, minor, micro); |
| 1762 | #else | 1762 | #else |
| 1763 | Vdbus_runtime_version = Qnil; | 1763 | Vdbus_runtime_version = Qnil; |
| 1764 | #endif | 1764 | #endif |
diff --git a/src/editfns.c b/src/editfns.c index fe119490f3f..f6d849fbc7a 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -2082,8 +2082,9 @@ the data it can't find. */) | |||
| 2082 | int m = offset / 60; | 2082 | int m = offset / 60; |
| 2083 | int am = offset < 0 ? - m : m; | 2083 | int am = offset < 0 ? - m : m; |
| 2084 | char buf[sizeof "+00" + INT_STRLEN_BOUND (int)]; | 2084 | char buf[sizeof "+00" + INT_STRLEN_BOUND (int)]; |
| 2085 | sprintf (buf, "%c%02d%02d", (offset < 0 ? '-' : '+'), am/60, am%60); | 2085 | zone_name = make_formatted_string (buf, "%c%02d%02d", |
| 2086 | zone_name = build_string (buf); | 2086 | (offset < 0 ? '-' : '+'), |
| 2087 | am / 60, am % 60); | ||
| 2087 | } | 2088 | } |
| 2088 | } | 2089 | } |
| 2089 | 2090 | ||
diff --git a/src/filelock.c b/src/filelock.c index 252ee3cfb1d..30258a5ffa0 100644 --- a/src/filelock.c +++ b/src/filelock.c | |||
| @@ -174,14 +174,14 @@ get_boot_time (void) | |||
| 174 | 174 | ||
| 175 | filename = Qnil; | 175 | filename = Qnil; |
| 176 | 176 | ||
| 177 | sprintf (cmd_string, "%s.%d", WTMP_FILE, counter); | 177 | tempname = make_formatted_string |
| 178 | tempname = build_string (cmd_string); | 178 | (cmd_string, "%s.%d", WTMP_FILE, counter); |
| 179 | if (! NILP (Ffile_exists_p (tempname))) | 179 | if (! NILP (Ffile_exists_p (tempname))) |
| 180 | filename = tempname; | 180 | filename = tempname; |
| 181 | else | 181 | else |
| 182 | { | 182 | { |
| 183 | sprintf (cmd_string, "%s.%d.gz", WTMP_FILE, counter); | 183 | tempname = make_formatted_string (cmd_string, "%s.%d.gz", |
| 184 | tempname = build_string (cmd_string); | 184 | WTMP_FILE, counter); |
| 185 | if (! NILP (Ffile_exists_p (tempname))) | 185 | if (! NILP (Ffile_exists_p (tempname))) |
| 186 | { | 186 | { |
| 187 | Lisp_Object args[6]; | 187 | Lisp_Object args[6]; |
diff --git a/src/frame.c b/src/frame.c index 4902811ecff..be5631da773 100644 --- a/src/frame.c +++ b/src/frame.c | |||
| @@ -518,9 +518,7 @@ make_terminal_frame (struct terminal *terminal) | |||
| 518 | XSETFRAME (frame, f); | 518 | XSETFRAME (frame, f); |
| 519 | Vframe_list = Fcons (frame, Vframe_list); | 519 | Vframe_list = Fcons (frame, Vframe_list); |
| 520 | 520 | ||
| 521 | tty_frame_count++; | 521 | f->name = make_formatted_string (name, "F%"pMd, ++tty_frame_count); |
| 522 | sprintf (name, "F%"pMd, tty_frame_count); | ||
| 523 | f->name = build_string (name); | ||
| 524 | 522 | ||
| 525 | f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */ | 523 | f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */ |
| 526 | f->async_visible = 1; /* Don't let visible be cleared later. */ | 524 | f->async_visible = 1; /* Don't let visible be cleared later. */ |
| @@ -2028,9 +2026,7 @@ set_term_frame_name (struct frame *f, Lisp_Object name) | |||
| 2028 | SBYTES (f->name))) | 2026 | SBYTES (f->name))) |
| 2029 | return; | 2027 | return; |
| 2030 | 2028 | ||
| 2031 | tty_frame_count++; | 2029 | name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count); |
| 2032 | sprintf (namebuf, "F%"pMd, tty_frame_count); | ||
| 2033 | name = build_string (namebuf); | ||
| 2034 | } | 2030 | } |
| 2035 | else | 2031 | else |
| 2036 | { | 2032 | { |
| @@ -3049,20 +3045,16 @@ x_report_frame_params (struct frame *f, Lisp_Object *alistptr) | |||
| 3049 | actually a pointer. Explicit casting avoids compiler | 3045 | actually a pointer. Explicit casting avoids compiler |
| 3050 | warnings. */ | 3046 | warnings. */ |
| 3051 | w = (unsigned long) FRAME_X_WINDOW (f); | 3047 | w = (unsigned long) FRAME_X_WINDOW (f); |
| 3052 | sprintf (buf, "%lu", w); | ||
| 3053 | store_in_alist (alistptr, Qwindow_id, | 3048 | store_in_alist (alistptr, Qwindow_id, |
| 3054 | build_string (buf)); | 3049 | make_formatted_string (buf, "%lu", w)); |
| 3055 | #ifdef HAVE_X_WINDOWS | 3050 | #ifdef HAVE_X_WINDOWS |
| 3056 | #ifdef USE_X_TOOLKIT | 3051 | #ifdef USE_X_TOOLKIT |
| 3057 | /* Tooltip frame may not have this widget. */ | 3052 | /* Tooltip frame may not have this widget. */ |
| 3058 | if (FRAME_X_OUTPUT (f)->widget) | 3053 | if (FRAME_X_OUTPUT (f)->widget) |
| 3059 | #endif | 3054 | #endif |
| 3060 | { | 3055 | w = (unsigned long) FRAME_OUTER_WINDOW (f); |
| 3061 | w = (unsigned long) FRAME_OUTER_WINDOW (f); | ||
| 3062 | sprintf (buf, "%lu", w); | ||
| 3063 | } | ||
| 3064 | store_in_alist (alistptr, Qouter_window_id, | 3056 | store_in_alist (alistptr, Qouter_window_id, |
| 3065 | build_string (buf)); | 3057 | make_formatted_string (buf, "%lu", w)); |
| 3066 | #endif | 3058 | #endif |
| 3067 | store_in_alist (alistptr, Qicon_name, f->icon_name); | 3059 | store_in_alist (alistptr, Qicon_name, f->icon_name); |
| 3068 | FRAME_SAMPLE_VISIBILITY (f); | 3060 | FRAME_SAMPLE_VISIBILITY (f); |
diff --git a/src/image.c b/src/image.c index 0854d017163..b4ad329bacb 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -8549,13 +8549,13 @@ gs_load (struct frame *f, struct image *img) | |||
| 8549 | don't either. Let the Lisp loader use `unwind-protect' instead. */ | 8549 | don't either. Let the Lisp loader use `unwind-protect' instead. */ |
| 8550 | printnum1 = FRAME_X_WINDOW (f); | 8550 | printnum1 = FRAME_X_WINDOW (f); |
| 8551 | printnum2 = img->pixmap; | 8551 | printnum2 = img->pixmap; |
| 8552 | sprintf (buffer, "%"pMu" %"pMu, printnum1, printnum2); | 8552 | window_and_pixmap_id |
| 8553 | window_and_pixmap_id = build_string (buffer); | 8553 | = make_formatted_string (buffer, "%"pMu" %"pMu, printnum1, printnum2); |
| 8554 | 8554 | ||
| 8555 | printnum1 = FRAME_FOREGROUND_PIXEL (f); | 8555 | printnum1 = FRAME_FOREGROUND_PIXEL (f); |
| 8556 | printnum2 = FRAME_BACKGROUND_PIXEL (f); | 8556 | printnum2 = FRAME_BACKGROUND_PIXEL (f); |
| 8557 | sprintf (buffer, "%"pMu" %"pMu, printnum1, printnum2); | 8557 | pixel_colors |
| 8558 | pixel_colors = build_string (buffer); | 8558 | = make_formatted_string (buffer, "%"pMu" %"pMu, printnum1, printnum2); |
| 8559 | 8559 | ||
| 8560 | XSETFRAME (frame, f); | 8560 | XSETFRAME (frame, f); |
| 8561 | loader = image_spec_value (img->spec, QCloader, NULL); | 8561 | loader = image_spec_value (img->spec, QCloader, NULL); |
diff --git a/src/lisp.h b/src/lisp.h index ca199190bc0..466287b798a 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -2611,6 +2611,7 @@ extern Lisp_Object list5 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, | |||
| 2611 | extern Lisp_Object allocate_misc (void); | 2611 | extern Lisp_Object allocate_misc (void); |
| 2612 | extern _Noreturn void string_overflow (void); | 2612 | extern _Noreturn void string_overflow (void); |
| 2613 | extern Lisp_Object make_string (const char *, ptrdiff_t); | 2613 | extern Lisp_Object make_string (const char *, ptrdiff_t); |
| 2614 | extern Lisp_Object make_formatted_string (char *, const char *, ...); | ||
| 2614 | extern Lisp_Object make_unibyte_string (const char *, ptrdiff_t); | 2615 | extern Lisp_Object make_unibyte_string (const char *, ptrdiff_t); |
| 2615 | extern Lisp_Object make_multibyte_string (const char *, ptrdiff_t, ptrdiff_t); | 2616 | extern Lisp_Object make_multibyte_string (const char *, ptrdiff_t, ptrdiff_t); |
| 2616 | extern Lisp_Object make_event_array (int, Lisp_Object *); | 2617 | extern Lisp_Object make_event_array (int, Lisp_Object *); |
diff --git a/src/minibuf.c b/src/minibuf.c index 89390aeb0b5..acf57a73268 100644 --- a/src/minibuf.c +++ b/src/minibuf.c | |||
| @@ -792,8 +792,8 @@ get_minibuffer (EMACS_INT depth) | |||
| 792 | buf = Fcar (tail); | 792 | buf = Fcar (tail); |
| 793 | if (NILP (buf) || NILP (BVAR (XBUFFER (buf), name))) | 793 | if (NILP (buf) || NILP (BVAR (XBUFFER (buf), name))) |
| 794 | { | 794 | { |
| 795 | sprintf (name, " *Minibuf-%"pI"d*", depth); | 795 | buf = Fget_buffer_create |
| 796 | buf = Fget_buffer_create (build_string (name)); | 796 | (make_formatted_string (name, " *Minibuf-%"pI"d*", depth)); |
| 797 | 797 | ||
| 798 | /* Although the buffer's name starts with a space, undo should be | 798 | /* Although the buffer's name starts with a space, undo should be |
| 799 | enabled in it. */ | 799 | enabled in it. */ |
diff --git a/src/msdos.c b/src/msdos.c index 64fc671fa43..8a6a150a956 100644 --- a/src/msdos.c +++ b/src/msdos.c | |||
| @@ -520,8 +520,10 @@ dos_set_window_size (int *rows, int *cols) | |||
| 520 | 520 | ||
| 521 | /* If the user specified a special video mode for these dimensions, | 521 | /* If the user specified a special video mode for these dimensions, |
| 522 | use that mode. */ | 522 | use that mode. */ |
| 523 | sprintf (video_name, "screen-dimensions-%dx%d", *rows, *cols); | 523 | video_mode |
| 524 | video_mode = Fsymbol_value (Fintern_soft (build_string (video_name), Qnil)); | 524 | = Fsymbol_value (Fintern_soft (make_formatted_string |
| 525 | (video_name, "screen-dimensions-%dx%d", | ||
| 526 | *rows, *cols), Qnil)); | ||
| 525 | 527 | ||
| 526 | if (INTEGERP (video_mode) | 528 | if (INTEGERP (video_mode) |
| 527 | && (video_mode_value = XINT (video_mode)) > 0) | 529 | && (video_mode_value = XINT (video_mode)) > 0) |
diff --git a/src/process.c b/src/process.c index f7ecd9b05a7..7e9d746a450 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -645,8 +645,7 @@ make_process (Lisp_Object name) | |||
| 645 | { | 645 | { |
| 646 | tem = Fget_process (name1); | 646 | tem = Fget_process (name1); |
| 647 | if (NILP (tem)) break; | 647 | if (NILP (tem)) break; |
| 648 | sprintf (suffix, "<%"pMd">", i); | 648 | name1 = concat2 (name, make_formatted_string (suffix, "<%"pMd">", i)); |
| 649 | name1 = concat2 (name, build_string (suffix)); | ||
| 650 | } | 649 | } |
| 651 | name = name1; | 650 | name = name1; |
| 652 | p->name = name; | 651 | p->name = name; |
diff --git a/src/xdisp.c b/src/xdisp.c index 9018dce37fa..4b9445d7469 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -9866,8 +9866,8 @@ ensure_echo_area_buffers (void) | |||
| 9866 | int j; | 9866 | int j; |
| 9867 | 9867 | ||
| 9868 | old_buffer = echo_buffer[i]; | 9868 | old_buffer = echo_buffer[i]; |
| 9869 | sprintf (name, " *Echo Area %d*", i); | 9869 | echo_buffer[i] = Fget_buffer_create |
| 9870 | echo_buffer[i] = Fget_buffer_create (build_string (name)); | 9870 | (make_formatted_string (name, " *Echo Area %d*", i)); |
| 9871 | BVAR (XBUFFER (echo_buffer[i]), truncate_lines) = Qnil; | 9871 | BVAR (XBUFFER (echo_buffer[i]), truncate_lines) = Qnil; |
| 9872 | /* to force word wrap in echo area - | 9872 | /* to force word wrap in echo area - |
| 9873 | it was decided to postpone this*/ | 9873 | it was decided to postpone this*/ |
diff --git a/src/xsettings.c b/src/xsettings.c index a4e3849a652..6f7b81cbe87 100644 --- a/src/xsettings.c +++ b/src/xsettings.c | |||
| @@ -711,10 +711,12 @@ apply_xft_settings (struct x_display_info *dpyinfo, | |||
| 711 | if (send_event_p) | 711 | if (send_event_p) |
| 712 | store_config_changed_event (Qfont_render, | 712 | store_config_changed_event (Qfont_render, |
| 713 | XCAR (dpyinfo->name_list_element)); | 713 | XCAR (dpyinfo->name_list_element)); |
| 714 | sprintf (buf, format, oldsettings.aa, oldsettings.hinting, | 714 | Vxft_settings |
| 715 | oldsettings.rgba, oldsettings.lcdfilter, | 715 | = make_formatted_string (buf, format, |
| 716 | oldsettings.hintstyle, oldsettings.dpi); | 716 | oldsettings.aa, oldsettings.hinting, |
| 717 | Vxft_settings = build_string (buf); | 717 | oldsettings.rgba, oldsettings.lcdfilter, |
| 718 | oldsettings.hintstyle, oldsettings.dpi); | ||
| 719 | |||
| 718 | } | 720 | } |
| 719 | else | 721 | else |
| 720 | FcPatternDestroy (pat); | 722 | FcPatternDestroy (pat); |