From c1a28fa9ae1a66dbd88c7a90d0fe72b0914b2f98 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Wed, 9 Nov 2005 15:13:00 +0000 Subject: [PATCH] in get_next_filename(), store the value of digits(ULONG_MAX) in a static, since it doesn't change and hence doesn't need to be recalculated git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3124 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 4 ++++ src/files.c | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 2bfca09e..f701bb62 100644 --- a/ChangeLog +++ b/ChangeLog @@ -91,6 +91,10 @@ CVS code - read_file() - Remove apparently unneeded logic to handle a case where current is NULL, since it shouldn't be NULL there. (DLR) + get_next_filename() + - Store the value of digits(ULONG_MAX) in a static, since it + doesn't change and hence doesn't need to be recalculated. + (DLR) - nano.c: do_verbatim_input() - Move to text.c, since it's an advanced text-based operation. diff --git a/src/files.c b/src/files.c index 233e06de..a7885dfa 100644 --- a/src/files.c +++ b/src/files.c @@ -628,16 +628,20 @@ int open_file(const char *filename, bool newfie, FILE **f) * extension exists, we return "". */ char *get_next_filename(const char *name, const char *suffix) { + static int ulmax_digits = -1; unsigned long i = 0; char *buf; size_t namelen, suffixlen; assert(name != NULL && suffix != NULL); + if (ulmax_digits == -1) + ulmax_digits = digits(ULONG_MAX); + namelen = strlen(name); suffixlen = strlen(suffix); - buf = charalloc(namelen + suffixlen + digits(ULONG_MAX) + 2); + buf = charalloc(namelen + suffixlen + ulmax_digits + 2); sprintf(buf, "%s%s", name, suffix); while (TRUE) { -- 2.39.5