Browse Source

* optimize fixpath, findfile to not require temp ansistrings
* check for verbosity for V_Tried level messages, patches from Sergei Gorelkin

git-svn-id: trunk@9297 -

peter 17 năm trước cách đây
mục cha
commit
241c65d5ec

+ 43 - 37
compiler/cfileutl.pas

@@ -117,12 +117,12 @@ interface
     Function  FileExists (const F : TCmdStr;allowcache:boolean) : Boolean;
     Function  FileExists (const F : TCmdStr;allowcache:boolean) : Boolean;
     function  FileExistsNonCase(const path,fn:TCmdStr;allowcache:boolean;var foundfile:TCmdStr):boolean;
     function  FileExistsNonCase(const path,fn:TCmdStr;allowcache:boolean;var foundfile:TCmdStr):boolean;
     Function  RemoveDir(d:TCmdStr):boolean;
     Function  RemoveDir(d:TCmdStr):boolean;
-    Function  FixPath(s:TCmdStr;allowdot:boolean):TCmdStr;
+    Function  FixPath(const s:TCmdStr;allowdot:boolean):TCmdStr;
     function  FixFileName(const s:TCmdStr):TCmdStr;
     function  FixFileName(const s:TCmdStr):TCmdStr;
     function  TargetFixPath(s:TCmdStr;allowdot:boolean):TCmdStr;
     function  TargetFixPath(s:TCmdStr;allowdot:boolean):TCmdStr;
     function  TargetFixFileName(const s:TCmdStr):TCmdStr;
     function  TargetFixFileName(const s:TCmdStr):TCmdStr;
     procedure SplitBinCmd(const s:TCmdStr;var bstr: TCmdStr;var cstr:TCmdStr);
     procedure SplitBinCmd(const s:TCmdStr;var bstr: TCmdStr;var cstr:TCmdStr);
-    function  FindFile(const f : TCmdStr;path : TCmdStr;allowcache:boolean;var foundfile:TCmdStr):boolean;
+    function  FindFile(const f : TCmdStr; const path : TCmdStr;allowcache:boolean;var foundfile:TCmdStr):boolean;
 {    function  FindFilePchar(const f : TCmdStr;path : pchar;allowcache:boolean;var foundfile:TCmdStr):boolean;}
 {    function  FindFilePchar(const f : TCmdStr;path : pchar;allowcache:boolean;var foundfile:TCmdStr):boolean;}
     function  FindExe(const bin:TCmdStr;allowcache:boolean;var foundfile:TCmdStr):boolean;
     function  FindExe(const bin:TCmdStr;allowcache:boolean;var foundfile:TCmdStr):boolean;
     function  GetShortName(const n:TCmdStr):TCmdStr;
     function  GetShortName(const n:TCmdStr):TCmdStr;
@@ -523,7 +523,7 @@ implementation
         else
         else
 {$endif usedircache}
 {$endif usedircache}
           Result:=SysUtils.FileExists(F);
           Result:=SysUtils.FileExists(F);
-        if assigned(do_comment) then
+        if do_checkverbosity(V_Tried) then
          begin
          begin
            if Result then
            if Result then
              do_comment(V_Tried,'Searching file '+F+'... found')
              do_comment(V_Tried,'Searching file '+F+'... found')
@@ -652,27 +652,37 @@ implementation
       end;
       end;
 
 
 
 
-    Function FixPath(s:TCmdStr;allowdot:boolean):TCmdStr;
+    Function FixPath(const s:TCmdStr;allowdot:boolean):TCmdStr;
       var
       var
-        i : longint;
+        i, L : longint;
+        P: PChar;
       begin
       begin
+        Result := s;
+        L := Length(Result);
+        if L=0 then
+          exit;
         { Fix separator }
         { Fix separator }
-        for i:=1 to length(s) do
-         if s[i] in ['/','\'] then
-          s[i]:=source_info.DirSep;
+        P := @Result[1];
+        for i:=0 to L-1 do
+          begin
+            if p^ in ['/','\'] then
+              p^:=source_info.DirSep;
+            inc(p);
+          end;
         { Fix ending / }
         { Fix ending / }
-        if (length(s)>0) and (s[length(s)]<>source_info.DirSep) and
-           (s[length(s)]<>DriveSeparator) then
-         s:=s+source_info.DirSep;
+        if (L>0) and (Result[L]<>source_info.DirSep) and
+           (Result[L]<>DriveSeparator) then
+          Result:=Result+source_info.DirSep;  { !still results in temp AnsiString }
         { Remove ./ }
         { Remove ./ }
-        if (not allowdot) and (s='.'+source_info.DirSep) then
-         s:='';
+        if (not allowdot) and ((Length(Result)=2) and (Result[1]='.') and (Result[2] = source_info.DirSep)) then
+          begin
+            Result:='';
+            Exit;
+          end;
         { return }
         { return }
-        if (tf_files_case_aware in source_info.flags) or
-           (tf_files_case_sensitive in source_info.flags) then
-         FixPath:=s
-        else
-         FixPath:=Lower(s);
+        if not ((tf_files_case_aware in source_info.flags) or
+           (tf_files_case_sensitive in source_info.flags)) then
+          Result := lower(Result);
       end;
       end;
 
 
   {Actually the version in macutils.pp could be used,
   {Actually the version in macutils.pp could be used,
@@ -945,7 +955,7 @@ implementation
 
 
        procedure WarnNonExistingPath(const path : TCmdStr);
        procedure WarnNonExistingPath(const path : TCmdStr);
        begin
        begin
-         if assigned(do_comment) then
+         if do_checkverbosity(V_Tried) then
            do_comment(V_Tried,'Path "'+path+'" not found');
            do_comment(V_Tried,'Path "'+path+'" not found');
        end;
        end;
 
 
@@ -1134,26 +1144,22 @@ implementation
      end;
      end;
 
 
 
 
-   function FindFile(const f : TCmdStr;path : TCmdStr;allowcache:boolean;var foundfile:TCmdStr):boolean;
-      Var
-        singlepathstring : TCmdStr;
-        i : longint;
+   function FindFile(const f : TCmdStr; const path : TCmdStr;allowcache:boolean;var foundfile:TCmdStr):boolean;
+     Var
+       StartPos, EndPos, L: LongInt;
      begin
      begin
-       if PathSeparator <> ';' then
-        for i:=1 to length(path) do
-         if path[i]=PathSeparator then
-          path[i]:=';';
-       FindFile:=false;
+       Result:=False;
+       StartPos := 1;
+       L := Length(Path);
        repeat
        repeat
-          i:=pos(';',path);
-          if i=0 then
-           i:=Succ (Length (Path));
-          singlepathstring:=FixPath(copy(path,1,i-1),false);
-          delete(path,1,i);
-          result:=FileExistsNonCase(singlepathstring,f,allowcache,FoundFile);
-          if result then
-            exit;
-       until path='';
+         EndPos := StartPos;
+         while (EndPos <= L) and ((Path[EndPos] <> PathSeparator) and (Path[EndPos] <> ';')) do
+           Inc(EndPos);
+         Result := FileExistsNonCase(FixPath(Copy(Path, StartPos, EndPos-StartPos), False), f, allowcache, FoundFile);
+         if Result then
+           Exit;
+         StartPos := EndPos + 1;
+       until StartPos > L;
        FoundFile:=f;
        FoundFile:=f;
      end;
      end;
 
 

+ 1 - 1
compiler/cmsgs.pas

@@ -383,7 +383,7 @@ begin
   if hp=nil then
   if hp=nil then
     Get:='msg nr '+tostr(nr)
     Get:='msg nr '+tostr(nr)
   else
   else
-    Get:=MsgReplace(strpas(hp),args);
+    Get:=MsgReplace(system.strpas(hp),args);
 end;
 end;
 
 
 end.
 end.

+ 9 - 0
compiler/comphook.pas

@@ -124,6 +124,7 @@ var
 Function  def_status:boolean;
 Function  def_status:boolean;
 Function  def_comment(Level:Longint;const s:ansistring):boolean;
 Function  def_comment(Level:Longint;const s:ansistring):boolean;
 function  def_internalerror(i:longint):boolean;
 function  def_internalerror(i:longint):boolean;
+function  def_CheckVerbosity(v:longint):boolean;
 procedure def_initsymbolinfo;
 procedure def_initsymbolinfo;
 procedure def_donesymbolinfo;
 procedure def_donesymbolinfo;
 procedure def_extractsymbolinfo;
 procedure def_extractsymbolinfo;
@@ -135,6 +136,7 @@ type
   tstatusfunction        = function:boolean;
   tstatusfunction        = function:boolean;
   tcommentfunction       = function(Level:Longint;const s:ansistring):boolean;
   tcommentfunction       = function(Level:Longint;const s:ansistring):boolean;
   tinternalerrorfunction = function(i:longint):boolean;
   tinternalerrorfunction = function(i:longint):boolean;
+  tcheckverbosityfunction = function(i:longint):boolean;
 
 
   tinitsymbolinfoproc = procedure;
   tinitsymbolinfoproc = procedure;
   tdonesymbolinfoproc = procedure;
   tdonesymbolinfoproc = procedure;
@@ -146,6 +148,7 @@ const
   do_status        : tstatusfunction  = @def_status;
   do_status        : tstatusfunction  = @def_status;
   do_comment       : tcommentfunction = @def_comment;
   do_comment       : tcommentfunction = @def_comment;
   do_internalerror : tinternalerrorfunction = @def_internalerror;
   do_internalerror : tinternalerrorfunction = @def_internalerror;
+  do_checkverbosity : tcheckverbosityfunction = @def_checkverbosity;
 
 
   do_initsymbolinfo : tinitsymbolinfoproc = @def_initsymbolinfo;
   do_initsymbolinfo : tinitsymbolinfoproc = @def_initsymbolinfo;
   do_donesymbolinfo : tdonesymbolinfoproc = @def_donesymbolinfo;
   do_donesymbolinfo : tdonesymbolinfoproc = @def_donesymbolinfo;
@@ -369,6 +372,12 @@ begin
   def_internalerror:=true;
   def_internalerror:=true;
 end;
 end;
 
 
+function def_CheckVerbosity(v:longint):boolean;
+begin
+  result:=status.use_bugreport or
+          ((status.verbosity and (v and V_LevelMask))=(v and V_LevelMask));
+end;
+
 procedure def_initsymbolinfo;
 procedure def_initsymbolinfo;
 begin
 begin
 end;
 end;

+ 8 - 4
compiler/fppu.pas

@@ -265,7 +265,8 @@ uses
 
 
          Function UnitExists(const ext:string;var foundfile:TCmdStr):boolean;
          Function UnitExists(const ext:string;var foundfile:TCmdStr):boolean;
          begin
          begin
-           Message1(unit_t_unitsearch,Singlepathstring+filename+ext);
+           if CheckVerbosity(V_Tried) then
+             Message1(unit_t_unitsearch,Singlepathstring+filename+ext);
            UnitExists:=FindFile(FileName+ext,Singlepathstring,true,foundfile);
            UnitExists:=FindFile(FileName+ext,Singlepathstring,true,foundfile);
          end;
          end;
 
 
@@ -382,16 +383,19 @@ uses
           begin
           begin
             { the full filename is specified so we can't use here the
             { the full filename is specified so we can't use here the
               searchpath (PFV) }
               searchpath (PFV) }
-            Message1(unit_t_unitsearch,ChangeFileExt(sourcefn^,sourceext));
+            if CheckVerbosity(V_Tried) then
+              Message1(unit_t_unitsearch,ChangeFileExt(sourcefn^,sourceext));
             fnd:=FindFile(ChangeFileExt(sourcefn^,sourceext),'',true,hs);
             fnd:=FindFile(ChangeFileExt(sourcefn^,sourceext),'',true,hs);
             if not fnd then
             if not fnd then
              begin
              begin
-               Message1(unit_t_unitsearch,ChangeFileExt(sourcefn^,pasext));
+               if CheckVerbosity(V_Tried) then
+                 Message1(unit_t_unitsearch,ChangeFileExt(sourcefn^,pasext));
                fnd:=FindFile(ChangeFileExt(sourcefn^,pasext),'',true,hs);
                fnd:=FindFile(ChangeFileExt(sourcefn^,pasext),'',true,hs);
              end;
              end;
             if not fnd and ((m_mac in current_settings.modeswitches) or (tf_p_ext_support in target_info.flags)) then
             if not fnd and ((m_mac in current_settings.modeswitches) or (tf_p_ext_support in target_info.flags)) then
              begin
              begin
-               Message1(unit_t_unitsearch,ChangeFileExt(sourcefn^,pext));
+               if CheckVerbosity(V_Tried) then
+                 Message1(unit_t_unitsearch,ChangeFileExt(sourcefn^,pext));
                fnd:=FindFile(ChangeFileExt(sourcefn^,pext),'',true,hs);
                fnd:=FindFile(ChangeFileExt(sourcefn^,pext),'',true,hs);
              end;
              end;
             if fnd then
             if fnd then

+ 1 - 2
compiler/verbose.pas

@@ -180,8 +180,7 @@ implementation
 
 
     function CheckVerbosity(v:longint):boolean;
     function CheckVerbosity(v:longint):boolean;
       begin
       begin
-        CheckVerbosity:=status.use_bugreport or
-                        ((status.verbosity and (v and V_LevelMask))=(v and V_LevelMask));
+        result:=do_checkverbosity(v);
       end;
       end;