Closed Bug 328357 Opened 18 years ago Closed 18 years ago

Codesize reduction of nsAppRunner.obj

Categories

(Core Graveyard :: Cmd-line Features, defect)

defect
Not set
normal

Tracking

(Not tracked)

VERIFIED FIXED
mozilla1.9alpha8

People

(Reporter: alfredkayser, Assigned: alfredkayser)

Details

Attachments

(1 file, 3 obsolete files)

Easy and quick codesize reduction of nsAppRunner.obj by more than 3 Kilobytes.

* Replace all multiple printf's with one printf with multiple strings
* Replace %s, HELP_SPACER_* with plain \t in the strings themselves.
* Inline two small functions only called from one place.
* Cleanup DumpVersion

Note, no functionality change at all!
Note, same kind of patch applies also to /toolkit/xre/nsAppRunner.cpp, where an allmost the same version of nsAppRunner.cpp exists.
Assignee: nobody → alfredkayser
Status: NEW → ASSIGNED
Attachment #212946 - Flags: review?(benjamin)
Attached patch Let's do both toolkit and xpfe (obsolete) — Splinter Review
Note, this saves about 3.5Kilobytes of codesize on Windows platform.
Attachment #212946 - Attachment is obsolete: true
Attachment #212946 - Flags: review?(benjamin)
> * Replace %s, HELP_SPACER_* with plain \t in the strings themselves.

You could keep the string macros, and allow the text to line up in the source, with code like:

printf("foo"      HELP_SPACER_2  "bar");
printf("foo baz"  HELP_SPACER_2  "bar foopy");

If you had a reason for removing the macros, feel free to ignore me.
Attachment #212952 - Flags: review?(benjamin)
The macros are removed because it just hinders code readability, and doesn't add any value.
Attachment #212952 - Flags: review?(benjamin) → review+
Attachment #212952 - Flags: superreview?(neil)
Comment on attachment 212952 [details] [diff] [review]
Let's do both toolkit and xpfe

>+  if (!arg || arg[0]=='\0' || arg[1]=='\0')
Nit: spaces around ==

>+  printf("%s %s, Copyright (c) 2003-2006 mozilla.org", 
>+         NS_STRINGIFY(MOZ_APP_DISPLAYNAME), NS_STRINGIFY(MOZ_APP_VERSION));
> 
>-  printf("%s %s, Copyright (c) 2003-2006 mozilla.org", NS_STRINGIFY(MOZ_APP_DISPLAYNAME), NS_STRINGIFY(MOZ_APP_VERSION));
>-
>-  if(buildID) {
>-    printf(", build %u\n", (unsigned int)buildID);
>+  if(NS_BUILD_ID) {
>+    printf(", build %u\n", (unsigned int)NS_BUILD_ID);
>   } else {
>     printf(" <developer build>\n");
>   }
I was going to nit you for missing the space between if and (, but then it occurred to me that this should be an #ifdef anyway. sr=me with that fixed. You could even drop the #ifdef inside the previous printf if you don't think that would be too confusing.
Attachment #212952 - Flags: superreview?(neil) → superreview+
Attachment #212952 - Attachment is obsolete: true
Who can do the checkin for me? Thanks in advance!
Whiteboard: checkin required
Who can do the check in for me? Thanks in advance, Alfred
Mark, can you do the checkin of this patch?
This is a simple patch but saves about 3K codesize!
Assignee: alfredkayser → mark
Status: ASSIGNED → NEW
Sure, I'll check in for you when I get to the office.
Assignee: mark → alfredkayser
Checked in on the trunk:
mozilla/toolkit/xre/nsAppRunner.cpp 1.141
mozilla/xpfe/bootstrap/nsAppRunner.cpp 1.453
Status: NEW → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
Whiteboard: checkin required
I think NS_BUILD_ID is always defined, but to 0000000000 when it's not an official build. So the original test was correct (and the compiler can optimize away |if (0) { ... }|). #if NS_BUILD_ID would probably also be fine.
I backed this out, since it caused tinderbox orange (btek).
-  return TranslateReturnValue(mainResult);
+  return NS_FAILED(rv) ? 1 : 0;

"Oops".
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Jag, an updated version of the patch, including the fixes for the two 'oops'...
Attachment #218404 - Attachment is obsolete: true
Attachment #231290 - Flags: superreview?
Attachment #231290 - Flags: superreview? → superreview?(jag)
Attachment #231290 - Flags: superreview?(jag) → superreview+
Comment on attachment 231290 [details] [diff] [review]
V3: With fixes for the build_id and mainResult

>-static nsresult DumpVersion(char *appname)
>+static inline void DumpVersion()
> {
>-  nsresult rv = NS_OK;
>   long buildID = NS_BUILD_ID;  // 10-digit number
>-
>-  printf("%s %s, Copyright (c) 2003-2006 mozilla.org", NS_STRINGIFY(MOZ_APP_DISPLAYNAME), NS_STRINGIFY(MOZ_APP_VERSION));
>-
>+  printf("%s %s, Copyright (c) 2003-2006 mozilla.org", 
>+         NS_STRINGIFY(MOZ_APP_DISPLAYNAME), NS_STRINGIFY(MOZ_APP_VERSION));
>   if(buildID) {
>     printf(", build %u\n", (unsigned int)buildID);
>   } else {
>     printf(" <developer build>\n");
>   }
>-
>-  return rv;
> }
You could have used the v1 version here (i.e. replacing buildID with NS_BUILD_ID) but if you do don't forget to the space: if (NS_BUILD_ID)
Just to be sure I kept the 'build_ID' code with the old code, as any change don't provide any benefits (except code cleaning...) but as seen above can have unwanted side effects.
Whiteboard: [checkin needed]
mozilla/xpfe/bootstrap/nsAppRunner.cpp 	1.457
mozilla/toolkit/xre/nsAppRunner.cpp 	1.150
Status: REOPENED → RESOLVED
Closed: 18 years ago18 years ago
Resolution: --- → FIXED
Whiteboard: [checkin needed]
Target Milestone: --- → mozilla1.9beta
Status: RESOLVED → VERIFIED
Product: Core → Core Graveyard
QA Contact: cmd-line
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: