From: fork0@t-online.de (Alex Riesen)
To: git@vger.kernel.org
Cc: Jon Loeliger <jdl@jdl.com>, Junio C Hamano <junkio@cox.net>
Subject: [PATCH] do not discard constness in interp_set_entry value argument
Date: Thu, 28 Sep 2006 21:12:55 +0200 [thread overview]
Message-ID: <20060928191255.GB4294@steel.home> (raw)
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
Actually, both of the struct interp's fields could be made const,
if not this interp_set_entry. And even then it could just return
the old value of ->value casting away its constness. I.e.:
struct interp
{
const char *name;
const char *value;
};
static inline char *interp_set_entry(struct interp *table, int slot, const char *value)
{
char *oldval = (char *)table[slot].value;
table[slot].value = newval;
return oldval;
}
The caller can than decide if it should be freed. This leaves
compiler with a chance to optimize something.
diff --git a/interpolate.c b/interpolate.c
index 62701d8..5d9d188 100644
--- a/interpolate.c
+++ b/interpolate.c
@@ -8,10 +8,10 @@ #include "git-compat-util.h"
#include "interpolate.h"
-void interp_set_entry(struct interp *table, int slot, char *value)
+void interp_set_entry(struct interp *table, int slot, const char *value)
{
char *oldval = table[slot].value;
- char *newval = value;
+ char *newval = NULL;
if (oldval)
free(oldval);
diff --git a/interpolate.h b/interpolate.h
index a55fb8e..190a180 100644
--- a/interpolate.h
+++ b/interpolate.h
@@ -16,7 +16,7 @@ struct interp {
char *value;
};
-extern void interp_set_entry(struct interp *table, int slot, char *value);
+extern void interp_set_entry(struct interp *table, int slot, const char *value);
extern void interp_clear_table(struct interp *table, int ninterps);
extern int interpolate(char *result, int reslen,
reply other threads:[~2006-09-28 19:13 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060928191255.GB4294@steel.home \
--to=fork0@t-online.de \
--cc=git@vger.kernel.org \
--cc=jdl@jdl.com \
--cc=junkio@cox.net \
--cc=raa.lkml@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox