From 78a32348568abae919a8bcc21d708232bb823eb5 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Sun, 1 Jul 2007 21:46:00 +0000 Subject: [PATCH] in nstrncasecmp() and mbstrncasecmp(), for efficiency, return zero immediately if s1 and s2 point to the same string git-svn-id: svn://svn.savannah.gnu.org/nano/branches/nano_2_0_branch/nano@4121 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 4 ++++ src/chars.c | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index 6efd1939..d45fcb0c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,10 @@ CVS code - wmouse_trafo(), which does both. Changes to do_browser(), do_mouse(), do_statusbar_mouse(), do_yesno_prompt(), and do_mouseinput(). (DLR) +- chars.c: + nstrncasecmp(), mbstrncasecmp() + - For efficiency, return zero immediately if s1 and s2 point to + the same string. (DLR) - prompt.c: do_yesno_prompt() - Remove redundant check for NO_HELP's being FALSE. (DLR) diff --git a/src/chars.c b/src/chars.c index 85ea80a4..9a79065a 100644 --- a/src/chars.c +++ b/src/chars.c @@ -506,6 +506,9 @@ int mbstrcasecmp(const char *s1, const char *s2) /* This function is equivalent to strncasecmp(). */ int nstrncasecmp(const char *s1, const char *s2, size_t n) { + if (s1 == s2) + return 0; + assert(s1 != NULL && s2 != NULL); for (; *s1 != '\0' && *s2 != '\0' && n > 0; s1++, s2++, n--) { @@ -526,6 +529,9 @@ int mbstrncasecmp(const char *s1, const char *s2, size_t n) char *s1_mb, *s2_mb; wchar_t ws1, ws2; + if (s1 == s2) + return 0; + assert(s1 != NULL && s2 != NULL); s1_mb = charalloc(MB_CUR_MAX); -- 2.39.5