Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2006-03

FExpand function

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Joao Morais

Hello,

Should this comparison (!) be fixed? Seeing that this code is going to be changed, what about change Pa[I] assignment from a variable to a constant?

<<rtl/inc/fexpand.inc>>

  (* Allow both '/' and '\' as directory separators *)
  (* by converting all to the native one.           *)
      if DirectorySeparator = '\' then
      {Allow slash as backslash}
        begin
          for I := 1 to Length (Pa) do
            if Pa [I] = '/' then
              Pa [I] := DirectorySeparator
        end
      else
!      if DirectorySeparator = '\' then
      {Allow backslash as slash}
          begin
            for I := 1 to Length (Pa) do
              if Pa [I] = '\' then
                Pa [I] := DirectorySeparator;
          end;

Thanks,

Joao Morais

Reply by email

Michael Van Canneyt
to Joao Morais
Joao Morais wrote 6 lines
Hello, Should this comparison (!) be fixed? Seeing that this code is going to be changed, what about change Pa[I] assignment from a variable to a constant?

The comparison can be fixed.

In fact I think the code can be reduced to a single loop:

if (DirectorySeparator='\') or (DirectorySeparator='/') then
  for I:=1 to Length(PA) do
    if (Pa[I] in ['\','/']) and (PA[I]DirectorySeparator) then
      Pa[I]:=DirectorySeparator;

Could you test this, please ?

Michael.

Show quoted text 28 lines
<<rtl/inc/fexpand.inc>> (* Allow both '/' and '\' as directory separators *) (* by converting all to the native one. *) if DirectorySeparator = '\' then {Allow slash as backslash} begin for I := 1 to Length (Pa) do if Pa [I] = '/' then Pa [I] := DirectorySeparator end else ! if DirectorySeparator = '\' then {Allow backslash as slash} begin for I := 1 to Length (Pa) do if Pa [I] = '\' then Pa [I] := DirectorySeparator; end; Thanks, -- Joao Morais _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Joao Morais
to Michael Van Canneyt
Michael Van Canneyt wrote 18 lines
On Sat, 4 Mar 2006, Joao Morais wrote: >Hello, > >Should this comparison (!) be fixed? Seeing that this code is going to >be changed, what about change Pa[I] assignment from a variable to a >constant? The comparison can be fixed. In fact I think the code can be reduced to a single loop: if (DirectorySeparator='\') or (DirectorySeparator='/') then for I:=1 to Length(PA) do if (Pa[I] in ['\','/']) and (PA[I]DirectorySeparator) then Pa[I]:=DirectorySeparator; Could you test this, please ?

It works.
Perhaps you could use the in operator in the first if.

Joao Morais

Reply by email

Tomas Hajny
to Michael Van Canneyt: The comparison can be fixed. In fact I think the code can be reduced to a single loop: if…
Michael Van Canneyt wrote
On Sat, 4 Mar 2006, Joao Morais wrote:

Hi,

> Should this comparison (!) be fixed? Seeing that this code is going to > be changed, what about change Pa[I] assignment from a variable to a > constant?

Fixed now, thanks a lot.

I replaced DirectorySeparator with the character
according to your suggestion too, but that didn't
really change anything, in fact -
DirectorySeparator is a constant too, so the code
generated for both versions is equal.

Show quoted text 8 lines
The comparison can be fixed. In fact I think the code can be reduced to a single loop: if (DirectorySeparator='\') or (DirectorySeparator='/') then for I:=1 to Length(PA) do if (Pa[I] in ['\','/']) and (PA[I]DirectorySeparator) then Pa[I]:=DirectorySeparator;

Preferably not, I guess. The current version
allows to optimize the unnecessary branch away
altogether. This version is probably considerably
slower.

Tomas

Reply by email