changeset 109791:af075a74e694

* keyboard.c (parse_tool_bar_item): Avoid excessive use of strlen.
author Andreas Schwab <schwab@linux-m68k.org>
date Sun, 15 Aug 2010 11:30:06 +0200
parents c34b730eb583
children 96094f59e6e2
files src/ChangeLog src/keyboard.c
diffstat 2 files changed, 21 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Sun Aug 15 10:13:02 2010 +0200
+++ b/src/ChangeLog	Sun Aug 15 11:30:06 2010 +0200
@@ -1,3 +1,7 @@
+2010-08-15  Andreas Schwab  <schwab@linux-m68k.org>
+
+	* keyboard.c (parse_tool_bar_item): Avoid excessive use of strlen.
+
 2010-08-15  Jan Djärv  <jan.h.d@swipnet.se>
 
 	* keyboard.c (parse_tool_bar_item): malloc buf.  Set TOOL_BAR_ITEM_LABEL
--- a/src/keyboard.c	Sun Aug 15 10:13:02 2010 +0200
+++ b/src/keyboard.c	Sun Aug 15 11:30:06 2010 +0200
@@ -8328,35 +8328,34 @@
       Lisp_Object capt = PROP (TOOL_BAR_ITEM_CAPTION);
       const char *label = SYMBOLP (key) ? (char *) SDATA (SYMBOL_NAME (key)) : "";
       const char *caption = STRINGP (capt) ? (char *) SDATA (capt) : "";
-      EMACS_INT max_lbl = 2*tool_bar_max_label_size;
-      char *buf = (char *) xmalloc (max_lbl+1);
+      EMACS_INT max_lbl = 2 * tool_bar_max_label_size;
+      char *buf = (char *) xmalloc (max_lbl + 1);
       Lisp_Object new_lbl;
-
-      if (strlen (caption) < max_lbl && caption[0] != '\0')
+      size_t caption_len = strlen (caption);
+
+      if (caption_len <= max_lbl && caption[0] != '\0')
         {
           strcpy (buf, caption);
-          while (buf[0] != '\0' && buf[strlen (buf) -1] == '.')
-            buf[strlen (buf)-1] = '\0';
-          if (strlen (buf) <= max_lbl)
-            caption = buf;
+          while (caption_len > 0 && buf[caption_len - 1] == '.')
+            caption_len--;
+	  buf[caption_len] = '\0';
+	  label = caption = buf;
         }
 
-      if (strlen (caption) <= max_lbl)
-        label = caption;
-
       if (strlen (label) <= max_lbl && label[0] != '\0')
         {
           int i;
-          if (label != buf) strcpy (buf, label);
-
-          for (i = 0; i < strlen (buf); ++i)
-            {
-              if (buf[i] == '-') buf[i] = ' ';
-            }
+          if (label != buf)
+	    strcpy (buf, label);
+
+          for (i = 0; buf[i] != '\0'; ++i)
+	    if (buf[i] == '-')
+	      buf[i] = ' ';
           label = buf;
 
         }
-      else label = "";
+      else
+	label = "";
 
       new_lbl = Fupcase_initials (make_string (label, strlen (label)));
       if (SCHARS (new_lbl) <= tool_bar_max_label_size)