public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] readelf: Lookup gettext "yes" and "no" only once.
Date: Mon, 04 Jun 2018 16:57:00 -0000	[thread overview]
Message-ID: <1528131447-14113-1-git-send-email-mark@klomp.org> (raw)

On my machine eu-readelf -N --debug-dump=info libxul.so > /dev/null
goes from 63 seconds to 57 seconds.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/ChangeLog |  7 +++++++
 src/readelf.c | 12 ++++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 19f4210..9ee9650 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,12 @@
 2018-06-04  Mark Wielaard  <mark@klomp.org>
 
+	* readelf.c (yes_str): New static char pointer.
+	(no_str): Likewise.
+	(main): Set yes_str and no_str using gettext.
+	(attr_callback): Use yes_str and no_str instead of calling gettext.
+
+2018-06-04  Mark Wielaard  <mark@klomp.org>
+
 	* readelf.c (main): Call __fsetlocking (stdout, FSETLOCKING_BYCALLER).
 
 2018-05-31  Mark Wielaard  <mark@klomp.org>
diff --git a/src/readelf.c b/src/readelf.c
index a578b27..81d1094 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -309,6 +309,10 @@ static void print_strings (Ebl *ebl);
 static void dump_archive_index (Elf *, const char *);
 
 
+/* Looked up once with gettext in main.  */
+static char *yes_str;
+static char *no_str;
+
 int
 main (int argc, char *argv[])
 {
@@ -321,6 +325,10 @@ main (int argc, char *argv[])
   /* Initialize the message catalog.  */
   textdomain (PACKAGE_TARNAME);
 
+  /* Look up once.  */
+  yes_str = gettext ("yes");
+  no_str = gettext ("yes");
+
   /* Parse and process arguments.  */
   int remaining;
   argp_parse (&argp, argc, argv, 0, &remaining, NULL);
@@ -7370,7 +7378,7 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
 
       printf ("           %*s%-20s (%s) %s\n",
 	      (int) (level * 2), "", dwarf_attr_name (attr),
-	      dwarf_form_name (form), flag ? gettext ("yes") : gettext ("no"));
+	      dwarf_form_name (form), flag ? yes_str : no_str);
       break;
 
     case DW_FORM_flag_present:
@@ -7378,7 +7386,7 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
 	break;
       printf ("           %*s%-20s (%s) %s\n",
 	      (int) (level * 2), "", dwarf_attr_name (attr),
-	      dwarf_form_name (form), gettext ("yes"));
+	      dwarf_form_name (form), yes_str);
       break;
 
     case DW_FORM_exprloc:
-- 
1.8.3.1

             reply	other threads:[~2018-06-04 16:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-04 16:57 Mark Wielaard [this message]
2018-06-06 20:36 ` Mark Wielaard

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=1528131447-14113-1-git-send-email-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).