Optimize pure C strings initialization.

* lisp.h (make_pure_string): Fix prototype.
(build_pure_c_string): New function, defined as static inline.  This
provides a better opportunity to optimize away calls to strlen when
the function is called with compile-time constant argument.
* alloc.c (make_pure_c_string): Fix comment.  Change to add nchars
argument, adjust users accordingly.  Use build_pure_c_string where
appropriate.
* buffer.c, coding.c, data.c, dbusbind.c, fileio.c, fontset.c, frame.c,
* keyboard.c, keymap.c, lread.c, search.c, syntax.c, w32fns.c, xdisp.c,
* xfaces.c, xfns.c, xterm.c: Use build_pure_c_string where appropriate.
This commit is contained in:
Dmitry Antipov 2012-07-10 12:43:46 +04:00
parent cb1caeaf2b
commit 2a0213a6d0
20 changed files with 73 additions and 52 deletions

View file

@ -1,3 +1,17 @@
2012-07-10 Dmitry Antipov <dmantipov@yandex.ru>
Optimize pure C strings initialization.
* lisp.h (make_pure_string): Fix prototype.
(build_pure_c_string): New function, defined as static inline. This
provides a better opportunity to optimize away calls to strlen when
the function is called with compile-time constant argument.
* alloc.c (make_pure_c_string): Fix comment. Change to add nchars
argument, adjust users accordingly. Use build_pure_c_string where
appropriate.
* buffer.c, coding.c, data.c, dbusbind.c, fileio.c, fontset.c, frame.c,
* keyboard.c, keymap.c, lread.c, search.c, syntax.c, w32fns.c, xdisp.c,
* xfaces.c, xfns.c, xterm.c: Use build_pure_c_string where appropriate.
2012-07-10 Dmitry Antipov <dmantipov@yandex.ru>
Avoid calls to strlen in miscellaneous functions.

View file

@ -5212,15 +5212,14 @@ make_pure_string (const char *data,
return string;
}
/* Return a string a string allocated in pure space. Do not allocate
the string data, just point to DATA. */
/* Return a string allocated in pure space. Do not
allocate the string data, just point to DATA. */
Lisp_Object
make_pure_c_string (const char *data)
make_pure_c_string (const char *data, ptrdiff_t nchars)
{
Lisp_Object string;
struct Lisp_String *s;
ptrdiff_t nchars = strlen (data);
s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String);
s->size = nchars;
@ -6842,7 +6841,7 @@ do hash-consing of the objects allocated to pure space. */);
not be able to allocate the memory to hold it. */
Vmemory_signal_data
= pure_cons (Qerror,
pure_cons (make_pure_c_string ("Memory exhausted--use M-x save-some-buffers then exit and restart Emacs"), Qnil));
pure_cons (build_pure_c_string ("Memory exhausted--use M-x save-some-buffers then exit and restart Emacs"), Qnil));
DEFVAR_LISP ("memory-full", Vmemory_full,
doc: /* Non-nil means Emacs cannot get much more Lisp memory. */);

View file

@ -4898,7 +4898,7 @@ init_buffer_once (void)
/* Must do these before making the first buffer! */
/* real setup is done in bindings.el */
BVAR (&buffer_defaults, mode_line_format) = make_pure_c_string ("%-");
BVAR (&buffer_defaults, mode_line_format) = build_pure_c_string ("%-");
BVAR (&buffer_defaults, header_line_format) = Qnil;
BVAR (&buffer_defaults, abbrev_mode) = Qnil;
BVAR (&buffer_defaults, overwrite_mode) = Qnil;
@ -5028,7 +5028,7 @@ init_buffer_once (void)
current_buffer = 0;
all_buffers = 0;
QSFundamental = make_pure_c_string ("Fundamental");
QSFundamental = build_pure_c_string ("Fundamental");
Qfundamental_mode = intern_c_string ("fundamental-mode");
BVAR (&buffer_defaults, major_mode) = Qfundamental_mode;
@ -5043,10 +5043,10 @@ init_buffer_once (void)
Fput (Qkill_buffer_hook, Qpermanent_local, Qt);
/* super-magic invisible buffer */
Vprin1_to_string_buffer = Fget_buffer_create (make_pure_c_string (" prin1"));
Vprin1_to_string_buffer = Fget_buffer_create (build_pure_c_string (" prin1"));
Vbuffer_alist = Qnil;
Fset_buffer (Fget_buffer_create (make_pure_c_string ("*scratch*")));
Fset_buffer (Fget_buffer_create (build_pure_c_string ("*scratch*")));
inhibit_modification_hooks = 0;
}
@ -5201,7 +5201,7 @@ syms_of_buffer (void)
Fput (Qprotected_field, Qerror_conditions,
pure_cons (Qprotected_field, pure_cons (Qerror, Qnil)));
Fput (Qprotected_field, Qerror_message,
make_pure_c_string ("Attempt to modify a protected field"));
build_pure_c_string ("Attempt to modify a protected field"));
DEFVAR_BUFFER_DEFAULTS ("default-mode-line-format",
mode_line_format,

View file

@ -10350,7 +10350,7 @@ syms_of_coding (void)
Vcode_conversion_reused_workbuf = Qnil;
staticpro (&Vcode_conversion_workbuf_name);
Vcode_conversion_workbuf_name = make_pure_c_string (" *code-conversion-work*");
Vcode_conversion_workbuf_name = build_pure_c_string (" *code-conversion-work*");
reused_workbuf_in_use = 0;
@ -10413,7 +10413,7 @@ syms_of_coding (void)
Fput (Qcoding_system_error, Qerror_conditions,
pure_cons (Qcoding_system_error, pure_cons (Qerror, Qnil)));
Fput (Qcoding_system_error, Qerror_message,
make_pure_c_string ("Invalid coding system"));
build_pure_c_string ("Invalid coding system"));
/* Intern this now in case it isn't already done.
Setting this variable twice is harmless.
@ -10686,22 +10686,22 @@ Also used for decoding keyboard input on X Window system. */);
DEFVAR_LISP ("eol-mnemonic-unix", eol_mnemonic_unix,
doc: /*
*String displayed in mode line for UNIX-like (LF) end-of-line format. */);
eol_mnemonic_unix = make_pure_c_string (":");
eol_mnemonic_unix = build_pure_c_string (":");
DEFVAR_LISP ("eol-mnemonic-dos", eol_mnemonic_dos,
doc: /*
*String displayed in mode line for DOS-like (CRLF) end-of-line format. */);
eol_mnemonic_dos = make_pure_c_string ("\\");
eol_mnemonic_dos = build_pure_c_string ("\\");
DEFVAR_LISP ("eol-mnemonic-mac", eol_mnemonic_mac,
doc: /*
*String displayed in mode line for MAC-like (CR) end-of-line format. */);
eol_mnemonic_mac = make_pure_c_string ("/");
eol_mnemonic_mac = build_pure_c_string ("/");
DEFVAR_LISP ("eol-mnemonic-undecided", eol_mnemonic_undecided,
doc: /*
*String displayed in mode line when end-of-line format is not yet determined. */);
eol_mnemonic_undecided = make_pure_c_string (":");
eol_mnemonic_undecided = build_pure_c_string (":");
DEFVAR_LISP ("enable-character-translation", Venable_character_translation,
doc: /*
@ -10839,7 +10839,7 @@ internal character representation. */);
plist[10] = intern_c_string (":for-unibyte");
plist[11] = args[coding_arg_for_unibyte] = Qt;
plist[12] = intern_c_string (":docstring");
plist[13] = make_pure_c_string ("Do no conversion.\n\
plist[13] = build_pure_c_string ("Do no conversion.\n\
\n\
When you visit a file with this coding, the file is read into a\n\
unibyte buffer as is, thus each byte of a file is treated as a\n\
@ -10857,7 +10857,7 @@ character.");
plist[8] = intern_c_string (":charset-list");
plist[9] = args[coding_arg_charset_list] = Fcons (Qascii, Qnil);
plist[11] = args[coding_arg_for_unibyte] = Qnil;
plist[13] = make_pure_c_string ("No conversion on encoding, automatic conversion on decoding.");
plist[13] = build_pure_c_string ("No conversion on encoding, automatic conversion on decoding.");
plist[15] = args[coding_arg_eol_type] = Qnil;
args[coding_arg_plist] = Flist (16, plist);
Fdefine_coding_system_internal (coding_arg_max, args);

View file

@ -3011,11 +3011,11 @@ syms_of_data (void)
Fput (Qerror, Qerror_conditions,
error_tail);
Fput (Qerror, Qerror_message,
make_pure_c_string ("error"));
build_pure_c_string ("error"));
#define PUT_ERROR(sym, tail, msg) \
Fput (sym, Qerror_conditions, pure_cons (sym, tail)); \
Fput (sym, Qerror_message, make_pure_c_string (msg))
Fput (sym, Qerror_message, build_pure_c_string (msg))
PUT_ERROR (Qquit, Qnil, "Quit");
@ -3042,7 +3042,7 @@ syms_of_data (void)
arith_tail = pure_cons (Qarith_error, error_tail);
Fput (Qarith_error, Qerror_conditions, arith_tail);
Fput (Qarith_error, Qerror_message, make_pure_c_string ("Arithmetic error"));
Fput (Qarith_error, Qerror_message, build_pure_c_string ("Arithmetic error"));
PUT_ERROR (Qbeginning_of_buffer, error_tail, "Beginning of buffer");
PUT_ERROR (Qend_of_buffer, error_tail, "End of buffer");

View file

@ -1712,7 +1712,7 @@ syms_of_dbusbind (void)
Fput (Qdbus_error, Qerror_conditions,
list2 (Qdbus_error, Qerror));
Fput (Qdbus_error, Qerror_message,
make_pure_c_string ("D-Bus error"));
build_pure_c_string ("D-Bus error"));
DEFSYM (QCdbus_system_bus, ":system");
DEFSYM (QCdbus_session_bus, ":session");
@ -1744,7 +1744,7 @@ syms_of_dbusbind (void)
Vdbus_compiled_version,
doc: /* The version of D-Bus Emacs is compiled against. */);
#ifdef DBUS_VERSION_STRING
Vdbus_compiled_version = make_pure_c_string (DBUS_VERSION_STRING);
Vdbus_compiled_version = build_pure_c_string (DBUS_VERSION_STRING);
#else
Vdbus_compiled_version = Qnil;
#endif

View file

@ -5647,17 +5647,17 @@ of file names regardless of the current language environment. */);
Fput (Qfile_error, Qerror_conditions,
Fpurecopy (list2 (Qfile_error, Qerror)));
Fput (Qfile_error, Qerror_message,
make_pure_c_string ("File error"));
build_pure_c_string ("File error"));
Fput (Qfile_already_exists, Qerror_conditions,
Fpurecopy (list3 (Qfile_already_exists, Qfile_error, Qerror)));
Fput (Qfile_already_exists, Qerror_message,
make_pure_c_string ("File already exists"));
build_pure_c_string ("File already exists"));
Fput (Qfile_date_error, Qerror_conditions,
Fpurecopy (list3 (Qfile_date_error, Qfile_error, Qerror)));
Fput (Qfile_date_error, Qerror_message,
make_pure_c_string ("Cannot set file date"));
build_pure_c_string ("Cannot set file date"));
DEFVAR_LISP ("file-name-handler-alist", Vfile_name_handler_alist,
doc: /* Alist of elements (REGEXP . HANDLER) for file names handled specially.

View file

@ -2164,7 +2164,7 @@ syms_of_fontset (void)
staticpro (&Vdefault_fontset);
FONTSET_ID (Vdefault_fontset) = make_number (0);
FONTSET_NAME (Vdefault_fontset)
= make_pure_c_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default");
= build_pure_c_string ("-*-*-*-*-*-*-*-*-*-*-*-*-fontset-default");
ASET (Vfontset_table, 0, Vdefault_fontset);
next_fontset_id = 1;
@ -2210,7 +2210,7 @@ alternate fontnames (if any) are tried instead. */);
DEFVAR_LISP ("fontset-alias-alist", Vfontset_alias_alist,
doc: /* Alist of fontset names vs the aliases. */);
Vfontset_alias_alist = Fcons (Fcons (FONTSET_NAME (Vdefault_fontset),
make_pure_c_string ("fontset-default")),
build_pure_c_string ("fontset-default")),
Qnil);
DEFVAR_LISP ("vertical-centering-font-regexp",

View file

@ -477,7 +477,7 @@ make_initial_frame (void)
Vframe_list = Fcons (frame, Vframe_list);
tty_frame_count = 1;
f->name = make_pure_c_string ("F1");
f->name = build_pure_c_string ("F1");
f->visible = 1;
f->async_visible = 1;

View file

@ -11441,7 +11441,7 @@ syms_of_keyboard (void)
pending_funcalls = Qnil;
staticpro (&pending_funcalls);
Vlispy_mouse_stem = make_pure_c_string ("mouse");
Vlispy_mouse_stem = build_pure_c_string ("mouse");
staticpro (&Vlispy_mouse_stem);
/* Tool-bars. */

View file

@ -3705,11 +3705,11 @@ syms_of_keymap (void)
Ffset (intern_c_string ("Control-X-prefix"), control_x_map);
exclude_keys
= pure_cons (pure_cons (make_pure_c_string ("DEL"), make_pure_c_string ("\\d")),
pure_cons (pure_cons (make_pure_c_string ("TAB"), make_pure_c_string ("\\t")),
pure_cons (pure_cons (make_pure_c_string ("RET"), make_pure_c_string ("\\r")),
pure_cons (pure_cons (make_pure_c_string ("ESC"), make_pure_c_string ("\\e")),
pure_cons (pure_cons (make_pure_c_string ("SPC"), make_pure_c_string (" ")),
= pure_cons (pure_cons (build_pure_c_string ("DEL"), build_pure_c_string ("\\d")),
pure_cons (pure_cons (build_pure_c_string ("TAB"), build_pure_c_string ("\\t")),
pure_cons (pure_cons (build_pure_c_string ("RET"), build_pure_c_string ("\\r")),
pure_cons (pure_cons (build_pure_c_string ("ESC"), build_pure_c_string ("\\e")),
pure_cons (pure_cons (build_pure_c_string ("SPC"), build_pure_c_string (" ")),
Qnil)))));
staticpro (&exclude_keys);

View file

@ -2626,7 +2626,15 @@ extern Lisp_Object make_string_from_bytes (const char *, ptrdiff_t, ptrdiff_t);
extern Lisp_Object make_specified_string (const char *,
ptrdiff_t, ptrdiff_t, int);
extern Lisp_Object make_pure_string (const char *, ptrdiff_t, ptrdiff_t, int);
extern Lisp_Object make_pure_c_string (const char *data);
extern Lisp_Object make_pure_c_string (const char *, ptrdiff_t);
/* Make a string allocated in pure space, use STR as string data. */
static inline Lisp_Object
build_pure_c_string (const char *str)
{
return make_pure_c_string (str, strlen (str));
}
/* Make a string from the data at STR, treating it as multibyte if the
data warrants. */

View file

@ -3700,7 +3700,7 @@ intern_c_string (const char *str)
with the extra copy. */
abort ();
return Fintern (make_pure_c_string (str), obarray);
return Fintern (make_pure_c_string (str, len), obarray);
}
DEFUN ("intern", Fintern, Sintern, 1, 2, 0,
@ -3941,7 +3941,7 @@ init_obarray (void)
initial_obarray = Vobarray;
staticpro (&initial_obarray);
Qunbound = Fmake_symbol (make_pure_c_string ("unbound"));
Qunbound = Fmake_symbol (build_pure_c_string ("unbound"));
/* Set temporary dummy values to Qnil and Vpurify_flag to satisfy the
NILP (Vpurify_flag) check in intern_c_string. */
Qnil = make_number (-1); Vpurify_flag = make_number (1);
@ -4441,8 +4441,8 @@ otherwise to default specified by file `epaths.h' when Emacs was built. */);
This list should not include the empty string.
`load' and related functions try to append these suffixes, in order,
to the specified file name if a Lisp suffix is allowed or required. */);
Vload_suffixes = Fcons (make_pure_c_string (".elc"),
Fcons (make_pure_c_string (".el"), Qnil));
Vload_suffixes = Fcons (build_pure_c_string (".elc"),
Fcons (build_pure_c_string (".el"), Qnil));
DEFVAR_LISP ("load-file-rep-suffixes", Vload_file_rep_suffixes,
doc: /* List of suffixes that indicate representations of \
the same file.
@ -4575,7 +4575,7 @@ from the file, and matches them against this regular expression.
When the regular expression matches, the file is considered to be safe
to load. See also `load-dangerous-libraries'. */);
Vbytecomp_version_regexp
= make_pure_c_string ("^;;;.\\(in Emacs version\\|bytecomp version FSF\\)");
= build_pure_c_string ("^;;;.\\(in Emacs version\\|bytecomp version FSF\\)");
Qlexical_binding = intern ("lexical-binding");
staticpro (&Qlexical_binding);

View file

@ -3056,12 +3056,12 @@ syms_of_search (void)
Fput (Qsearch_failed, Qerror_conditions,
pure_cons (Qsearch_failed, pure_cons (Qerror, Qnil)));
Fput (Qsearch_failed, Qerror_message,
make_pure_c_string ("Search failed"));
build_pure_c_string ("Search failed"));
Fput (Qinvalid_regexp, Qerror_conditions,
pure_cons (Qinvalid_regexp, pure_cons (Qerror, Qnil)));
Fput (Qinvalid_regexp, Qerror_message,
make_pure_c_string ("Invalid regexp"));
build_pure_c_string ("Invalid regexp"));
last_thing_searched = Qnil;
staticpro (&last_thing_searched);

View file

@ -3475,7 +3475,7 @@ syms_of_syntax (void)
Fput (Qscan_error, Qerror_conditions,
pure_cons (Qscan_error, pure_cons (Qerror, Qnil)));
Fput (Qscan_error, Qerror_message,
make_pure_c_string ("Scan error"));
build_pure_c_string ("Scan error"));
DEFVAR_BOOL ("parse-sexp-ignore-comments", parse_sexp_ignore_comments,
doc: /* Non-nil means `forward-sexp', etc., should treat comments as whitespace. */);

View file

@ -6798,7 +6798,7 @@ syms_of_w32fns (void)
Fput (Qundefined_color, Qerror_conditions,
pure_cons (Qundefined_color, pure_cons (Qerror, Qnil)));
Fput (Qundefined_color, Qerror_message,
make_pure_c_string ("Undefined color"));
build_pure_c_string ("Undefined color"));
staticpro (&w32_grabbed_keys);
w32_grabbed_keys = Qnil;

View file

@ -28728,7 +28728,7 @@ syms_of_xdisp (void)
staticpro (&echo_area_buffer[0]);
staticpro (&echo_area_buffer[1]);
Vmessages_buffer_name = make_pure_c_string ("*Messages*");
Vmessages_buffer_name = build_pure_c_string ("*Messages*");
staticpro (&Vmessages_buffer_name);
mode_line_proptrans_alist = Qnil;
@ -28809,7 +28809,7 @@ See also `overlay-arrow-string'. */);
DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string,
doc: /* String to display as an arrow in non-window frames.
See also `overlay-arrow-position'. */);
Voverlay_arrow_string = make_pure_c_string ("=>");
Voverlay_arrow_string = build_pure_c_string ("=>");
DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list,
doc: /* List of variables (symbols) which hold markers for overlay arrows.
@ -28915,10 +28915,10 @@ and is used only on frames for which no explicit name has been set
Vicon_title_format
= Vframe_title_format
= pure_cons (intern_c_string ("multiple-frames"),
pure_cons (make_pure_c_string ("%b"),
pure_cons (build_pure_c_string ("%b"),
pure_cons (pure_cons (empty_unibyte_string,
pure_cons (intern_c_string ("invocation-name"),
pure_cons (make_pure_c_string ("@"),
pure_cons (build_pure_c_string ("@"),
pure_cons (intern_c_string ("system-name"),
Qnil)))),
Qnil)));

View file

@ -6643,7 +6643,7 @@ that number of fonts when searching for a matching font. */);
This stipple pattern is used on monochrome displays
instead of shades of gray for a face background color.
See `set-face-stipple' for possible values for this variable. */);
Vface_default_stipple = make_pure_c_string ("gray3");
Vface_default_stipple = build_pure_c_string ("gray3");
DEFVAR_LISP ("tty-defined-color-alist", Vtty_defined_color_alist,
doc: /* An alist of defined terminal colors and their RGB values.

View file

@ -5828,7 +5828,7 @@ syms_of_xfns (void)
Fput (Qundefined_color, Qerror_conditions,
pure_cons (Qundefined_color, pure_cons (Qerror, Qnil)));
Fput (Qundefined_color, Qerror_message,
make_pure_c_string ("Undefined color"));
build_pure_c_string ("Undefined color"));
DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape,
doc: /* The shape of the pointer when over text.

View file

@ -10845,7 +10845,7 @@ syms_of_xterm (void)
last_mouse_press_frame = Qnil;
#ifdef USE_GTK
xg_default_icon_file = make_pure_c_string ("icons/hicolor/scalable/apps/emacs.svg");
xg_default_icon_file = build_pure_c_string ("icons/hicolor/scalable/apps/emacs.svg");
staticpro (&xg_default_icon_file);
DEFSYM (Qx_gtk_map_stock, "x-gtk-map-stock");