From 1130ecfcacce9743078221b956cd07b352776442 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Tue, 26 Jun 2012 09:00:30 +0400 Subject: [PATCH] * src/alloc.c: Remove build_string. * src/lisp.h: Define build_string as static inline. This provides a better opportunity to optimize away calls to strlen when the function is called with compile-time constant argument. * src/image.c (imagemagick_error): Convert to build_string. * src/w32proc.c (sys_spawnve): Likewise. * src/xterm.c (x_term_init): Likewise. * admin/coccinelle/build_string.cocci: Semantic patch to convert from make_string to build_string. --- admin/ChangeLog | 5 +++++ admin/coccinelle/build_string.cocci | 6 ++++++ src/ChangeLog | 10 ++++++++++ src/alloc.c | 10 ---------- src/image.c | 2 +- src/lisp.h | 11 ++++++++++- src/w32proc.c | 2 +- src/xterm.c | 2 +- 8 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 admin/coccinelle/build_string.cocci diff --git a/admin/ChangeLog b/admin/ChangeLog index 44856f4b44..d983bb0229 100644 --- a/admin/ChangeLog +++ b/admin/ChangeLog @@ -1,3 +1,8 @@ +2012-06-26 Dmitry Antipov + + * coccinelle/build_string.cocci: Semantic patch + to convert from make_string to build_string. + 2012-06-24 Dmitry Antipov First Coccinelle semantic patch. diff --git a/admin/coccinelle/build_string.cocci b/admin/coccinelle/build_string.cocci new file mode 100644 index 0000000000..d47727018d --- /dev/null +++ b/admin/coccinelle/build_string.cocci @@ -0,0 +1,6 @@ +// Convert simple cases to build_string. +@@ +identifier I; +@@ +- make_string (I, strlen (I)) ++ build_string (I) diff --git a/src/ChangeLog b/src/ChangeLog index 5b3387b813..ff3fa02790 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2012-06-26 Dmitry Antipov + + * alloc.c: Remove build_string. + * lisp.h: Define build_string as static inline. This provides + a better opportunity to optimize away calls to strlen when the + function is called with compile-time constant argument. + * image.c (imagemagick_error): Convert to build_string. + * w32proc.c (sys_spawnve): Likewise. + * xterm.c (x_term_init): Likewise. + 2012-06-26 Paul Eggert Use sprintf return value instead of invoking strlen on result. diff --git a/src/alloc.c b/src/alloc.c index 490632f282..6f7cc968b8 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -2496,16 +2496,6 @@ make_specified_string (const char *contents, } -/* Make a string from the data at STR, treating it as multibyte if the - data warrants. */ - -Lisp_Object -build_string (const char *str) -{ - return make_string (str, strlen (str)); -} - - /* Return an unibyte Lisp_String set up to hold LENGTH characters occupying LENGTH bytes. */ diff --git a/src/image.c b/src/image.c index c5f7be3e75..cc0ddbb77e 100644 --- a/src/image.c +++ b/src/image.c @@ -7570,7 +7570,7 @@ imagemagick_error (MagickWand *wand) description = MagickGetException (wand, &severity); image_error ("ImageMagick error: %s", - make_string (description, strlen (description)), + build_string (description), Qnil); description = (char *) MagickRelinquishMemory (description); } diff --git a/src/lisp.h b/src/lisp.h index d6cc886bae..cac5370bd1 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -2700,7 +2700,6 @@ EXFUN (Fmake_symbol, 1); EXFUN (Fmake_marker, 0); extern _Noreturn void string_overflow (void); EXFUN (Fmake_string, 2); -extern Lisp_Object build_string (const char *); extern Lisp_Object make_string (const char *, ptrdiff_t); extern Lisp_Object make_unibyte_string (const char *, ptrdiff_t); extern Lisp_Object make_multibyte_string (const char *, ptrdiff_t, ptrdiff_t); @@ -2713,6 +2712,16 @@ extern Lisp_Object make_specified_string (const char *, EXFUN (Fpurecopy, 1); extern Lisp_Object make_pure_string (const char *, ptrdiff_t, ptrdiff_t, int); extern Lisp_Object make_pure_c_string (const char *data); + +/* Make a string from the data at STR, treating it as multibyte if the + data warrants. */ + +static inline Lisp_Object +build_string (const char *str) +{ + return make_string (str, strlen (str)); +} + extern Lisp_Object pure_cons (Lisp_Object, Lisp_Object); EXFUN (Fgarbage_collect, 0); extern void make_byte_code (struct Lisp_Vector *); diff --git a/src/w32proc.c b/src/w32proc.c index 2f5f39e68b..3864d15623 100644 --- a/src/w32proc.c +++ b/src/w32proc.c @@ -777,7 +777,7 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp) } /* Handle executable names without an executable suffix. */ - program = make_string (cmdname, strlen (cmdname)); + program = build_string (cmdname); if (NILP (Ffile_executable_p (program))) { struct gcpro gcpro1; diff --git a/src/xterm.c b/src/xterm.c index f398e4dbb2..be01513d91 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -10036,7 +10036,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) const char *file = "~/.emacs.d/gtkrc"; Lisp_Object s, abs_file; - s = make_string (file, strlen (file)); + s = build_string (file); abs_file = Fexpand_file_name (s, Qnil); if (! NILP (abs_file) && !NILP (Ffile_readable_p (abs_file))) -- 2.20.1