From 6499394c780c80b92e73498f13ce9b4a624df437 Mon Sep 17 00:00:00 2001 From: Bill Meier Date: Sun, 30 Jun 2013 23:03:20 +0000 Subject: Declare slist[] as static (reduces storage & code executed: *See below); Declare dlist[] similarly to slist[] (not really needed since generated storage/code was OK as is) *On Windows the following program generates sub-optimal code (when built using VC10 or VC11 with CFLAGS as used when building Wireshark). void foo(void) { const char *const zz[] = {"ABC", "abc"}; } ------------- Code generated: _DATA SEGMENT $SG1013 DB 'ABC', 00H !!! note string stored twice !! $SG1014 DB 'ABC', 00H $SG1015 DB 'abc', 00H $SG1016 DB 'abc', 00H _DATA ENDS ; 1 : void foo(void) { push ebp mov ebp, esp sub esp, 8 ; 2 : const char *const zz[] = {"ABC", "abc"}; mov DWORD PTR _zz$[ebp], OFFSET $SG1014 !! note: each ptr of array mov DWORD PTR _zz$[ebp+4], OFFSET $SG1016 !! individually pushed on stack Not shown: Declaring zz as 'static' generates much better code.... svn path=/trunk/; revision=50271 --- epan/column.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'epan') diff --git a/epan/column.c b/epan/column.c index e25252b54c..cef7241778 100644 --- a/epan/column.c +++ b/epan/column.c @@ -43,7 +43,7 @@ string */ const gchar * col_format_to_string(const gint fmt) { - const gchar *slist[] = { + static const gchar *const slist[NUM_COL_FMTS] = { "%q", /* 0) COL_8021Q_VLAN_ID */ "%Yt", /* 1) COL_ABS_DATE_TIME */ "%At", /* 2) COL_ABS_TIME */ @@ -115,7 +115,9 @@ col_format_to_string(const gint fmt) { /* Given a format number (as defined in column_info.h), returns its description */ -static const gchar *dlist[NUM_COL_FMTS] = { +const gchar * +col_format_desc(const gint fmt) { + static const gchar *const dlist[NUM_COL_FMTS] = { "802.1Q VLAN id", /* 0) COL_8021Q_VLAN_ID */ "Absolute date and time", /* 1) COL_ABS_DATE_TIME */ "Absolute time", /* 2) COL_ABS_TIME */ @@ -177,10 +179,8 @@ static const gchar *dlist[NUM_COL_FMTS] = { "UTC date and time", /* 58) COL_UTC_DATE_TIME */ "UTC time", /* 59) COL_UTC_TIME */ "Time (format as specified)" /* 60) COL_CLS_TIME */ -}; + }; -const gchar * -col_format_desc(const gint fmt) { g_assert((fmt >= 0) && (fmt < NUM_COL_FMTS)); return(dlist[fmt]); } -- cgit v1.2.3