From 7ccca2e4386c74501abc68d184ac4ab2989cec18 Mon Sep 17 00:00:00 2001 From: yury Date: Sat, 22 Jul 2006 09:29:54 +0000 Subject: [PATCH] * Optimization for smartlinking. Removed command line parsing in system unit initialization for wince. The parser is called when command line is accessed first time in program. It saves 1.55KB exe size, when command line is not used. git-svn-id: trunk@4275 - --- rtl/inc/systemh.inc | 2 ++ rtl/wince/system.pp | 76 +++++++++++++++++++++++++++++---------------- 2 files changed, 51 insertions(+), 27 deletions(-) diff --git a/rtl/inc/systemh.inc b/rtl/inc/systemh.inc index 44adede424..7b86f036fa 100644 --- a/rtl/inc/systemh.inc +++ b/rtl/inc/systemh.inc @@ -322,7 +322,9 @@ const fmInOut = $D7B3; fmAppend = $D7B4; Filemode : byte = 2; +{$ifndef HAS_CMDLINE} CmdLine : PChar = nil; +{$endif HAS_CMDLINE} (* Value should be changed during system initialization as appropriate. *) { assume that this program will not spawn other threads, when the diff --git a/rtl/wince/system.pp b/rtl/wince/system.pp index 8dc0a8e1a0..e2f052b70f 100644 --- a/rtl/wince/system.pp +++ b/rtl/wince/system.pp @@ -23,6 +23,7 @@ interface {$define WINCE_EXCEPTION_HANDLING} {$define DISABLE_NO_THREAD_MANAGER} +{$define HAS_CMDLINE} { include system-independent routine headers } {$I systemh.inc} @@ -54,9 +55,6 @@ const Thread_count : longint = 0; var -{ C compatible arguments } - argc : longint; - argv : ppchar; { WinCE Info } hprevinst, MainInstance, @@ -181,6 +179,11 @@ function muls(s1,s2 : single) : single; compilerproc; function divs(s1,s2 : single) : single; compilerproc; {$endif CPUARM} +function CmdLine: PChar; +{ C compatible arguments } +function argc: longint; +function argv: ppchar; + implementation var @@ -556,6 +559,11 @@ begin GetCommandFile:=@ModuleName; end; +var + Fargc: longint; + Fargv: ppchar; + FCmdLine: PChar; + procedure setup_arguments; var arglen, @@ -573,38 +581,38 @@ var begin oldargvlen:=argvlen; argvlen:=(idx+8) and (not 7); - sysreallocmem(argv,argvlen*sizeof(pointer)); - fillchar(argv[oldargvlen],(argvlen-oldargvlen)*sizeof(pointer),0); + sysreallocmem(Fargv,argvlen*sizeof(pointer)); + fillchar(Fargv[oldargvlen],(argvlen-oldargvlen)*sizeof(pointer),0); end; { use realloc to reuse already existing memory } { always allocate, even if length is zero, since } { the arg. is still present! } - sysreallocmem(argv[idx],len+1); + sysreallocmem(Fargv[idx],len+1); end; begin { create commandline, it starts with the executed filename which is argv[0] } { WinCE passes the command NOT via the args, but via getmodulefilename} - argv:=nil; + if FCmdLine <> nil then exit; argvlen:=0; pc:=getcommandfile; Arglen:=0; while pc[Arglen] <> #0 do Inc(Arglen); allocarg(0,arglen); - move(pc^,argv[0]^,arglen+1); - { Setup cmdline variable } + move(pc^,Fargv[0]^,arglen+1); + { Setup FCmdLine variable } arg:=PChar(GetCommandLine); count:=WideToAnsiBuf(PWideChar(arg), -1, nil, 0); - cmdline:=SysGetMem(arglen + count + 3); - cmdline^:='"'; - move(pc^, (cmdline + 1)^, arglen); - (cmdline + arglen + 1)^:='"'; - (cmdline + arglen + 2)^:=' '; - WideToAnsiBuf(PWideChar(arg), -1, cmdline + arglen + 3, count); + FCmdLine:=SysGetMem(arglen + count + 3); + FCmdLine^:='"'; + move(pc^, (FCmdLine + 1)^, arglen); + (FCmdLine + arglen + 1)^:='"'; + (FCmdLine + arglen + 2)^:=' '; + WideToAnsiBuf(PWideChar(arg), -1, FCmdLine + arglen + 3, count); { process arguments } count:=0; - pc:=cmdline; + pc:=FCmdLine; {$IfDef SYSTEM_DEBUG_STARTUP} Writeln(stderr,'WinCE GetCommandLine is #',pc,'#'); {$EndIf } @@ -675,7 +683,7 @@ begin allocarg(count,arglen); quote:=' '; pc:=argstart; - arg:=argv[count]; + arg:=Fargv[count]; while (pc^<>#0) do begin case pc^ of @@ -740,17 +748,34 @@ begin arg^:=#0; end; {$IfDef SYSTEM_DEBUG_STARTUP} - Writeln(stderr,'dos arg ',count,' #',arglen,'#',argv[count],'#'); + Writeln(stderr,'dos arg ',count,' #',arglen,'#',Fargv[count],'#'); {$EndIf SYSTEM_DEBUG_STARTUP} inc(count); end; { get argc and create an nil entry } - argc:=count; + Fargc:=count; allocarg(argc,0); { free unused memory } - sysreallocmem(argv,(argc+1)*sizeof(pointer)); + sysreallocmem(Fargv,(argc+1)*sizeof(pointer)); end; +function CmdLine: PChar; +begin + setup_arguments; + Result:=FCmdLine; +end; + +function argc: longint; +begin + setup_arguments; + Result:=Fargc; +end; + +function argv: ppchar; +begin + setup_arguments; + Result:=Fargv; +end; function paramcount : longint; begin @@ -759,19 +784,18 @@ end; function paramstr(l : longint) : string; begin - if (l>=0) and (l=0) and (l