Patchwork Eliminate version string duplication

login
register
about
Submitter Carl-Daniel Hailfinger
Date 2009-07-22 15:52:50
Message ID <4A6735D2.2090301@gmx.net>
Download mbox | patch
Permalink /patch/61/
State Accepted
Commit r659
Headers show

Comments

Carl-Daniel Hailfinger - 2009-07-22 15:52:50
Eliminate version string duplication.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Stefan Reinauer - 2009-07-22 17:26:42
On 7/22/09 5:52 PM, Carl-Daniel Hailfinger wrote:
> Eliminate version string duplication.
>   

Are you sure the string is ever duplicated? GCC should optimize this...

Anyways,

Acked-by: Stefan Reinauer <stepan@coresystems.de>

> Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
>
> Index: flashrom-versionstring_once/flash.h
> ===================================================================
> --- flashrom-versionstring_once/flash.h	(Revision 657)
> +++ flashrom-versionstring_once/flash.h	(Arbeitskopie)
> @@ -379,6 +379,7 @@
>  
>  /* flashrom.c */
>  extern int verbose;
> +extern const char *flashrom_version;
>  #define printf_debug(x...) { if (verbose) printf(x); }
>  void map_flash_registers(struct flashchip *flash);
>  int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len);
> Index: flashrom-versionstring_once/flashrom.c
> ===================================================================
> --- flashrom-versionstring_once/flashrom.c	(Revision 657)
> +++ flashrom-versionstring_once/flashrom.c	(Arbeitskopie)
> @@ -30,6 +30,7 @@
>  #include "flash.h"
>  #include "flashchips.h"
>  
> +const char *flashrom_version = FLASHROM_VERSION;
>  char *chip_to_probe = NULL;
>  int verbose = 0;
>  int programmer = PROGRAMMER_INTERNAL;
> @@ -503,7 +504,7 @@
>  
>  void print_version(void)
>  {
> -	printf("flashrom v%s\n", FLASHROM_VERSION);
> +	printf("flashrom v%s\n", flashrom_version);
>  }
>  
>  int main(int argc, char *argv[])
> Index: flashrom-versionstring_once/print.c
> ===================================================================
> --- flashrom-versionstring_once/print.c	(Revision 657)
> +++ flashrom-versionstring_once/print.c	(Arbeitskopie)
> @@ -718,7 +718,7 @@
>  {
>  	time_t t = time(NULL);
>  
> -	printf(wiki_header, ctime(&t), FLASHROM_VERSION);
> +	printf(wiki_header, ctime(&t), flashrom_version);
>  	print_supported_chips_wiki();
>  	print_supported_chipsets_wiki();
>  	print_supported_boards_wiki();
>
>
>
Carl-Daniel Hailfinger - 2009-07-22 20:13:45
On 22.07.2009 19:26, Stefan Reinauer wrote:
> On 7/22/09 5:52 PM, Carl-Daniel Hailfinger wrote:
>   
>> Eliminate version string duplication.
>>   
>>     
>
> Are you sure the string is ever duplicated? GCC should optimize this...
>   

The string ends up in two different compilation units, so the linker
would have to perform this analysis.

> Acked-by: Stefan Reinauer <stepan@coresystems.de>
>   

Thanks, r659.

Regards,
Carl-Daniel

Patch

Index: flashrom-versionstring_once/flash.h
===================================================================
--- flashrom-versionstring_once/flash.h	(Revision 657)
+++ flashrom-versionstring_once/flash.h	(Arbeitskopie)
@@ -379,6 +379,7 @@ 
 
 /* flashrom.c */
 extern int verbose;
+extern const char *flashrom_version;
 #define printf_debug(x...) { if (verbose) printf(x); }
 void map_flash_registers(struct flashchip *flash);
 int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len);
Index: flashrom-versionstring_once/flashrom.c
===================================================================
--- flashrom-versionstring_once/flashrom.c	(Revision 657)
+++ flashrom-versionstring_once/flashrom.c	(Arbeitskopie)
@@ -30,6 +30,7 @@ 
 #include "flash.h"
 #include "flashchips.h"
 
+const char *flashrom_version = FLASHROM_VERSION;
 char *chip_to_probe = NULL;
 int verbose = 0;
 int programmer = PROGRAMMER_INTERNAL;
@@ -503,7 +504,7 @@ 
 
 void print_version(void)
 {
-	printf("flashrom v%s\n", FLASHROM_VERSION);
+	printf("flashrom v%s\n", flashrom_version);
 }
 
 int main(int argc, char *argv[])
Index: flashrom-versionstring_once/print.c
===================================================================
--- flashrom-versionstring_once/print.c	(Revision 657)
+++ flashrom-versionstring_once/print.c	(Arbeitskopie)
@@ -718,7 +718,7 @@ 
 {
 	time_t t = time(NULL);
 
-	printf(wiki_header, ctime(&t), FLASHROM_VERSION);
+	printf(wiki_header, ctime(&t), flashrom_version);
 	print_supported_chips_wiki();
 	print_supported_chipsets_wiki();
 	print_supported_boards_wiki();