From d672ac3c611453c624948ed8cc2ced65cadc3400 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 13 Nov 2013 17:52:18 -0800 Subject: Prefer tail calls. * lib-src/ebrowse.c (xstrdup): * lib-src/etags.c (savenstr): * lwlib/lwlib.c (safe_strdup): * src/xfns.c (xic_create_fontsetname): * src/xrdb.c (gethomedir): Prefer tail calls. * lib-src/etags.c (concat): Omit unnecessary assignment. --- lib-src/ChangeLog | 6 ++++++ lib-src/ebrowse.c | 2 +- lib-src/etags.c | 8 ++------ lwlib/ChangeLog | 4 ++++ lwlib/lwlib.c | 6 +----- src/ChangeLog | 5 +++++ src/xfns.c | 2 +- src/xrdb.c | 4 +--- 8 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index 44d7260dead..2010444743a 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,3 +1,9 @@ +2013-11-14 Paul Eggert + + * ebrowse.c (xstrdup): + * etags.c (savenstr): Prefer tail calls. + * etags.c (concat): Omit unnecessary assignment. + 2013-10-24 Glenn Morris * Makefile.in ($(DESTDIR)${archlibdir}): diff --git a/lib-src/ebrowse.c b/lib-src/ebrowse.c index 216865c3800..971f74e7fee 100644 --- a/lib-src/ebrowse.c +++ b/lib-src/ebrowse.c @@ -514,7 +514,7 @@ static char * xstrdup (char *s) { if (s) - s = strcpy (xmalloc (strlen (s) + 1), s); + return strcpy (xmalloc (strlen (s) + 1), s); return s; } diff --git a/lib-src/etags.c b/lib-src/etags.c index aa8c773e357..21cf3654b9e 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c @@ -6243,12 +6243,9 @@ savestr (const char *cp) static char * savenstr (const char *cp, int len) { - register char *dp; - - dp = xnew (len + 1, char); - memcpy (dp, cp, len); + char *dp = xnew (len + 1, char); dp[len] = '\0'; - return dp; + return memcpy (dp, cp, len); } /* @@ -6362,7 +6359,6 @@ concat (const char *s1, const char *s2, const char *s3) strcpy (result, s1); strcpy (result + len1, s2); strcpy (result + len1 + len2, s3); - result[len1 + len2 + len3] = '\0'; return result; } diff --git a/lwlib/ChangeLog b/lwlib/ChangeLog index dadb13514e0..e4ab1a91cac 100644 --- a/lwlib/ChangeLog +++ b/lwlib/ChangeLog @@ -1,3 +1,7 @@ +2013-11-14 Paul Eggert + + * lwlib.c (safe_strdup): Prefer tail calls. + 2013-11-02 Glenn Morris Use relative filenames in TAGS files. diff --git a/lwlib/lwlib.c b/lwlib/lwlib.c index 7d9920e8bce..c8eba9cf35e 100644 --- a/lwlib/lwlib.c +++ b/lwlib/lwlib.c @@ -103,11 +103,7 @@ static void show_one_widget_busy (Widget, Boolean); char * safe_strdup (const char *s) { - char *result; - if (! s) return 0; - result = (char *) xmalloc (strlen (s) + 1); - strcpy (result, s); - return result; + return s ? xstrdup (s) : 0; } static void diff --git a/src/ChangeLog b/src/ChangeLog index 08bbe9e69d2..3861449cf5a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2013-11-14 Paul Eggert + + * xfns.c (xic_create_fontsetname): + * xrdb.c (gethomedir): Prefer tail calls. + 2013-11-12 Paul Eggert * xterm.c (syms_of_xterm): staticpro Qmodifier_value, Qalt, Qhyper, diff --git a/src/xfns.c b/src/xfns.c index 42e7c2eeec5..46f377042f6 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -1750,7 +1750,7 @@ xic_create_fontsetname (const char *base_fontname, int motif) } } if (motif) - strcat (fontsetname, ":"); + return strcat (fontsetname, ":"); return fontsetname; } #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */ diff --git a/src/xrdb.c b/src/xrdb.c index 52988f0818a..ea823b2b313 100644 --- a/src/xrdb.c +++ b/src/xrdb.c @@ -234,9 +234,7 @@ gethomedir (void) copy = xmalloc (strlen (ptr) + 2); strcpy (copy, ptr); - strcat (copy, "/"); - - return copy; + return strcat (copy, "/"); } -- cgit v1.2.1