Recent

Author Topic: Updates to fpc sources - optimization & consolidation  (Read 488 times)

ydd

  • New Member
  • *
  • Posts: 48
Updates to fpc sources - optimization & consolidation
« on: March 02, 2021, 01:34:24 am »
During code analysis there are many places which could be very easily optimized and/or consolidated

example for optimization:

Code: Pascal  [Select][+][-]
  1. Procedure DoDirSeparators (Var FileName : PathStr); {$ifdef FPC_HAS_CPSTRING}rtlproc;{$endif}
  2.  
  3. VAr I : longint;
  4.  
  5. begin
  6.   For I:=1 to Length(FileName) do
  7.     If CharInSet(FileName[I],AllowDirectorySeparators) then
  8.       FileName[i]:=DirectorySeparator;
  9. end;
  10.  

in my case FileName has '/', which is replaced in cycle with the same value, but for each assignment <fpc_ansistr_unique> is called

for consolidation - I prefer Delphi sources style, so:
- Procedure - should be procedure, and no space between DoDirSeparators and (
- VAr I : longint;
  should be:
  var
    i: Longint;
  without enter before & after
  also var name is declared as I, but used as I and i
- code: For I:=1 to Length(FileName) do
  should be:
    for i := 1 to Length(FileName) do
- code: FileName:=DirectorySeparator;
  should be:
    FileName := DirectorySeparator;

How I can take part in code updates and devote my time to make FPC better?

kimof

  • Newbie
  • Posts: 2
Re: Updates to fpc sources - optimization & consolidation
« Reply #1 on: March 02, 2021, 01:43:03 am »
Hey, I don't get that ? Where do you want to put the code ?

ydd

  • New Member
  • *
  • Posts: 48
Re: Updates to fpc sources - optimization & consolidation
« Reply #2 on: March 02, 2021, 01:47:06 am »
Hey, I don't get that ? Where do you want to put the code ?

update FPC sources

ccrause

  • Sr. Member
  • ****
  • Posts: 380
Re: Updates to fpc sources - optimization & consolidation
« Reply #3 on: March 02, 2021, 08:43:22 am »
...
for consolidation - I prefer Delphi sources style, so:
...

I also prefer the so called Delphi style, but please keep in mind the following:
  • Coding style is a preference so there isn't a right or wrong style
  • Changing coding style would muddle the commit history
  • The semi-definitive coding style for compiler and RTL
The so called coding style is also not consistently applied in all files, so the general rule is to adapt your coding style to the surrounding code - the basic rule as far as I can see is first to commit a file sets the style.

How I can take part in code updates and devote my time to make FPC better?
One can submit an "issue"  on the bug tracker. An issue can either be a real bug (compiler crashes, produces incorrect results) or code enhancement/optimization or new functionality.  An example (most recently modified compiler issue): https://bugs.freepascal.org/view.php?id=38560

One can also discuss potential changes on one of the fpc mailing lists (https://lists.freepascal.org/mailman/listinfo).

PascalDragon

  • Hero Member
  • *****
  • Posts: 2980
  • Compiler Developer
Re: Updates to fpc sources - optimization & consolidation
« Reply #4 on: March 02, 2021, 09:08:15 am »
in my case FileName has '/', which is replaced in cycle with the same value, but for each assignment <fpc_ansistr_unique> is called

It could probably be improved like this (not tested):

Code: Pascal  [Select][+][-]
  1. Procedure DoDirSeparators (Var FileName : PathStr); {$ifdef FPC_HAS_CPSTRING}rtlproc;{$endif}
  2.  
  3. Var I : longint;
  4.     S: PathPChar;
  5. begin
  6.   S:=Nil;
  7.   For I:=1 to Length(FileName) do
  8.     If CharInSet(FileName[I],AllowDirectorySeparators) then
  9.       begin
  10.         If not Assigned(S) then
  11.           begin
  12.             UniqueString(FileName);
  13.             S:=PathPChar(FileName);
  14.           end;
  15.         S[i]:=DirectorySeparator;
  16.       end;
  17. end;

for consolidation - I prefer Delphi sources style, so:

It does not matter what you prefer. When contributing to an open source project you adhere to the style of the project. Things like this are often not up to discussion (which is the case for us). Not to mention that code style changes are unnecessary noise in the commit history. (Though that VAr bugs me as well... fixed in r48862)

ASBzone

  • Hero Member
  • *****
  • Posts: 616
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: Updates to fpc sources - optimization & consolidation
« Reply #5 on: March 03, 2021, 07:53:34 pm »
(Though that VAr bugs me as well... fixed in r48862)

LOL!!  :D :D
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.0.13 r64843 / FPC v3.2.1-r49055 (via FpcUpDeluxe) -- Windows 64-bit install w/Win32 and Linux/Arm cross-compiles
Primary System: Windows 10 Pro x64, Version 2009 (Build 19042)
Other Systems: Windows 10 Pro x64, Version 2009 (Build 19042) or greater

 

TinyPortal © 2005-2018