Recent

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

ydd

  • Jr. Member
  • **
  • Posts: 78
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?

ydd

  • Jr. Member
  • **
  • Posts: 78
Re: Updates to fpc sources - optimization & consolidation
« Reply #1 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

  • Hero Member
  • *****
  • Posts: 845
Re: Updates to fpc sources - optimization & consolidation
« Reply #2 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: 5446
  • Compiler Developer
Re: Updates to fpc sources - optimization & consolidation
« Reply #3 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: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: Updates to fpc sources - optimization & consolidation
« Reply #4 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.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

 

TinyPortal © 2005-2018