chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
util: optimize free_and_strdup() if NOP
[elogind.git]
/
src
/
shared
/
util.c
diff --git
a/src/shared/util.c
b/src/shared/util.c
index 275fdece1e70de1d9534179a925d191f8fa1ae5c..b885a46e439fb3a5a197007b4ff90690fa0c074e 100644
(file)
--- a/
src/shared/util.c
+++ b/
src/shared/util.c
@@
-5683,6
+5683,9
@@
int free_and_strdup(char **p, const char *s) {
/* Replaces a string pointer with an strdup()ed new string,
* possibly freeing the old one. */
/* Replaces a string pointer with an strdup()ed new string,
* possibly freeing the old one. */
+ if (streq_ptr(*p, s))
+ return 0;
+
if (s) {
t = strdup(s);
if (!t)
if (s) {
t = strdup(s);
if (!t)
@@
-5693,7
+5696,7
@@
int free_and_strdup(char **p, const char *s) {
free(*p);
*p = t;
free(*p);
*p = t;
- return
0
;
+ return
1
;
}
int sethostname_idempotent(const char *s) {
}
int sethostname_idempotent(const char *s) {