Before this bad practice of using arrays of string pointers to constant
strings further spreads let's fix it. With this change not only is the
entire data associated with the arrays read-only, it also replaces a
memory lookup with a trivial arithmetic operation. The result is
a smaller and faster binary.
Signed-off-by: Ulrich Drepper <[email protected]>
diff --git a/tools/perf/arch/sparc/util/dwarf-regs.c b/tools/perf/arch/sparc/util/dwarf-regs.c
index 0ab8848..17f193e 100644
--- a/tools/perf/arch/sparc/util/dwarf-regs.c
+++ b/tools/perf/arch/sparc/util/dwarf-regs.c
@@ -14,7 +14,7 @@
#define SPARC_MAX_REGS 96
-const char *sparc_regs_table[SPARC_MAX_REGS] = {
+static const char sparc_regs_table[SPARC_MAX_REGS][5] = {
"%g0", "%g1", "%g2", "%g3", "%g4", "%g5", "%g6", "%g7",
"%o0", "%o1", "%o2", "%o3", "%o4", "%o5", "%sp", "%o7",
"%l0", "%l1", "%l2", "%l3", "%l4", "%l5", "%l6", "%l7",
diff --git a/tools/perf/arch/x86/util/dwarf-regs.c b/tools/perf/arch/x86/util/dwarf-regs.c
index a794d30..fe5ef0f 100644
--- a/tools/perf/arch/x86/util/dwarf-regs.c
+++ b/tools/perf/arch/x86/util/dwarf-regs.c
@@ -28,7 +28,7 @@
*/
#define X86_32_MAX_REGS 8
-const char *x86_32_regs_table[X86_32_MAX_REGS] = {
+static const char x86_32_regs_table[X86_32_MAX_REGS][7] = {
"%ax",
"%cx",
"%dx",
@@ -40,7 +40,7 @@ const char *x86_32_regs_table[X86_32_MAX_REGS] = {
};
#define X86_64_MAX_REGS 16
-const char *x86_64_regs_table[X86_64_MAX_REGS] = {
+static const char x86_64_regs_table[X86_64_MAX_REGS][5] = {
"%ax",
"%dx",
"%cx",
Em Thu, Jul 22, 2010 at 12:11:49PM -0400, Ulrich Drepper escreveu:
> Before this bad practice of using arrays of string pointers to constant
> strings further spreads let's fix it. With this change not only is the
> entire data associated with the arrays read-only, it also replaces a
> memory lookup with a trivial arithmetic operation. The result is
> a smaller and faster binary.
>
>
> Signed-off-by: Ulrich Drepper <[email protected]>
Thanks, applying to perf/core (i.e. for 2.6.36).
- Arnaldo