From: "Anthony G. Basile" <blueness@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/elfix:master commit in: misc/install.wrapper.c/
Date: Sat, 18 Jan 2014 23:25:46 +0000 (UTC) [thread overview]
Message-ID: <1390087568.30fe7e70b82961b660892c4f33812303a3d4583a.blueness@gentoo> (raw)
commit: 30fe7e70b82961b660892c4f33812303a3d4583a
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Jan 18 23:26:08 2014 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Jan 18 23:26:08 2014 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=30fe7e70
misc/install.wrapper.c: speed up memory allocation with realloc
---
misc/install.wrapper.c/checkcopyattrs.sh | 5 +++++
misc/install.wrapper.c/install.wrapper.c | 25 +++++++++++++++++++------
2 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/misc/install.wrapper.c/checkcopyattrs.sh b/misc/install.wrapper.c/checkcopyattrs.sh
index 584970a..86a6a33 100755
--- a/misc/install.wrapper.c/checkcopyattrs.sh
+++ b/misc/install.wrapper.c/checkcopyattrs.sh
@@ -4,6 +4,7 @@ set -e
touch a b c
mkdir -p d e
setfattr -n user.foo -v "bar" a
+setfattr -n user.bas -v "x" a
setfattr -n user.pax.flags -v "mr" a
setfattr -n user.pax.flags -v "p" b
setfattr -n user.pax.flags -v "r" c
@@ -13,6 +14,7 @@ setfattr -n user.pax.flags -v "r" c
./install-xattr c z
[ "$(getfattr --only-values -n user.foo x)" == "bar" ]
+[ "$(getfattr --only-values -n user.bas x)" == "x" ]
[ "$(getfattr --only-values -n user.pax.flags x)" == "mr" ]
[ "$(getfattr --only-values -n user.pax.flags y)" == "p" ]
[ "$(getfattr --only-values -n user.pax.flags z)" == "r" ]
@@ -20,6 +22,7 @@ setfattr -n user.pax.flags -v "r" c
./install-xattr a b c d
[ "$(getfattr --only-values -n user.foo d/a)" == "bar" ]
+[ "$(getfattr --only-values -n user.bas d/a)" == "x" ]
[ "$(getfattr --only-values -n user.pax.flags d/a)" == "mr" ]
[ "$(getfattr --only-values -n user.pax.flags d/b)" == "p" ]
[ "$(getfattr --only-values -n user.pax.flags d/c)" == "r" ]
@@ -27,10 +30,12 @@ setfattr -n user.pax.flags -v "r" c
./install-xattr -t e a b c
[ "$(getfattr --only-values -n user.foo e/a)" == "bar" ]
+[ "$(getfattr --only-values -n user.bas e/a)" == "x" ]
[ "$(getfattr --only-values -n user.pax.flags e/a)" == "mr" ]
[ "$(getfattr --only-values -n user.pax.flags e/b)" == "p" ]
[ "$(getfattr --only-values -n user.pax.flags e/c)" == "r" ]
./install-xattr a -D f/a
[ "$(getfattr --only-values -n user.foo f/a)" == "bar" ]
+[ "$(getfattr --only-values -n user.bas f/a)" == "x" ]
[ "$(getfattr --only-values -n user.pax.flags f/a)" == "mr" ]
diff --git a/misc/install.wrapper.c/install.wrapper.c b/misc/install.wrapper.c/install.wrapper.c
index 2d588ac..b79d90c 100644
--- a/misc/install.wrapper.c/install.wrapper.c
+++ b/misc/install.wrapper.c/install.wrapper.c
@@ -38,6 +38,15 @@ xmalloc(size_t size)
return ret;
}
+static void *
+xrealloc(void *p, size_t size)
+{
+ void *ret = realloc(p, size);
+ if (ret == NULL)
+ err(1, "realloc() failed");
+ return ret;
+}
+
static char *
path_join(const char *path, const char *file)
{
@@ -88,7 +97,9 @@ copyxattr(const char *source, const char *target)
{
ssize_t i, j; /* counters to walk through strings */
ssize_t lsize, xsize; /* size in bytes of the list of xattrs and the values */
- char *lxattr, *value; /* string of xattr names and the values */
+ char *lxattr; /* string of xattr names */
+ static char *value = NULL ; /* string of an xattr name's value */
+ static size_t value_size = 0; /* size of the value string */
lsize = xlistxattr(source, NULL, 0);
lxattr = xmalloc(lsize);
@@ -116,12 +127,12 @@ copyxattr(const char *source, const char *target)
}
xsize = xgetxattr(source, &lxattr[i-1], 0, 0);
- if (xsize > 0) {
- value = xmalloc(xsize);
- xgetxattr(source, &lxattr[i-1], value, xsize);
- xsetxattr(target, &lxattr[i-1], value, xsize);
- free(value);
+ if (xsize > value_size) {
+ value_size = xsize;
+ value = xrealloc(value, value_size);
}
+ xgetxattr(source, &lxattr[i-1], value, xsize);
+ xsetxattr(target, &lxattr[i-1], value, xsize);
skip:
while (lxattr[i++] != 0)
@@ -130,6 +141,8 @@ copyxattr(const char *source, const char *target)
break;
}
+ /* No need to free(value) on return because its static and we */
+ /* just keep reusing the same allocated memory on each call. */
free(lxattr);
}
next reply other threads:[~2014-01-18 23:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-18 23:25 Anthony G. Basile [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-02-07 18:10 [gentoo-commits] proj/elfix:master commit in: misc/install.wrapper.c/ Anthony G. Basile
2014-02-07 18:10 Anthony G. Basile
2014-01-20 19:02 Anthony G. Basile
2014-01-18 23:39 Anthony G. Basile
2014-01-18 20:57 Anthony G. Basile
2014-01-18 20:30 Anthony G. Basile
2014-01-18 20:23 Anthony G. Basile
2014-01-18 20:06 Anthony G. Basile
2014-01-18 13:18 Anthony G. Basile
2014-01-18 13:18 Anthony G. Basile
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=1390087568.30fe7e70b82961b660892c4f33812303a3d4583a.blueness@gentoo \
--to=blueness@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/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