View Issue Details

IDProjectCategoryView StatusLast Update
0033475FPCRTLpublic2018-03-21 18:16
ReportersilvioprogAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Product Version3.1.1Product Build 
Target Version3.2.0Fixed in Version3.1.1 
Summary0033475: [patch] adds TStrings.AddPair() for Delphi compatibility
DescriptionHello.

Patch in attachment.
Additional InformationTStrings.AddPair()'s doc: http://docwiki.embarcadero.com/Libraries/Tokyo/en/System.Classes.TStrings.AddPair
TagsNo tags attached.
Fixed in Revision38587
FPCOldBugId
FPCTarget
Attached Files
  • 0001-Patch-from-silvioprog-to-implement-TStrings.AddPair-.patch (1,884 bytes)
    From 3ff6b077ae0f1d725893677d84474c5a6385ef48 Mon Sep 17 00:00:00 2001
    From: silvioprog <silvioprog@gmail.com>
    Date: Tue, 20 Mar 2018 21:01:17 -0300
    Subject: [PATCH 1/1] * Patch from silvioprog to implement TStrings.AddPair()
     for Delphi compatibility.
    
    ---
     rtl/objpas/classes/classesh.inc |  2 ++
     rtl/objpas/classes/stringl.inc  | 11 +++++++++++
     2 files changed, 13 insertions(+)
    
    diff --git a/rtl/objpas/classes/classesh.inc b/rtl/objpas/classes/classesh.inc
    index ad8654f..06543c7 100644
    --- a/rtl/objpas/classes/classesh.inc
    +++ b/rtl/objpas/classes/classesh.inc
    @@ -668,6 +668,8 @@ type
         function AddObject(const S: string; AObject: TObject): Integer; virtual; overload;
         function Add(const Fmt : string; const Args : Array of const): Integer; overload;
         function AddObject(const Fmt: string; Args : Array of const; AObject: TObject): Integer; overload;
    +    function AddPair(const AName, AValue: string): TStrings; overload;
    +    function AddPair(const AName, AValue: string; AObject: TObject): TStrings; overload;
         procedure Append(const S: string);
         procedure AddStrings(TheStrings: TStrings); overload; virtual;
         procedure AddStrings(TheStrings: TStrings; ClearFirst : Boolean); overload;
    diff --git a/rtl/objpas/classes/stringl.inc b/rtl/objpas/classes/stringl.inc
    index 907c115..f32769a 100644
    --- a/rtl/objpas/classes/stringl.inc
    +++ b/rtl/objpas/classes/stringl.inc
    @@ -758,6 +758,17 @@ begin
       Result:=AddObject(Format(Fmt,Args),AObject);
     end;
     
    +function TStrings.AddPair(const AName, AValue: string): TStrings;
    +begin
    +  Result := Self;
    +  Add(Concat(AName, NameValueSeparator, AValue));
    +end;
    +
    +function TStrings.AddPair(const AName, AValue: string; AObject: TObject): TStrings;
    +begin
    +  Result := Self;
    +  AddObject(Concat(AName, NameValueSeparator, AValue), AObject);
    +end;
     
     Procedure TStrings.Append(const S: string);
     
    -- 
    2.7.4
    
    

Activities

silvioprog

2018-03-21 01:06

reporter  

0001-Patch-from-silvioprog-to-implement-TStrings.AddPair-.patch (1,884 bytes)
From 3ff6b077ae0f1d725893677d84474c5a6385ef48 Mon Sep 17 00:00:00 2001
From: silvioprog <silvioprog@gmail.com>
Date: Tue, 20 Mar 2018 21:01:17 -0300
Subject: [PATCH 1/1] * Patch from silvioprog to implement TStrings.AddPair()
 for Delphi compatibility.

---
 rtl/objpas/classes/classesh.inc |  2 ++
 rtl/objpas/classes/stringl.inc  | 11 +++++++++++
 2 files changed, 13 insertions(+)

diff --git a/rtl/objpas/classes/classesh.inc b/rtl/objpas/classes/classesh.inc
index ad8654f..06543c7 100644
--- a/rtl/objpas/classes/classesh.inc
+++ b/rtl/objpas/classes/classesh.inc
@@ -668,6 +668,8 @@ type
     function AddObject(const S: string; AObject: TObject): Integer; virtual; overload;
     function Add(const Fmt : string; const Args : Array of const): Integer; overload;
     function AddObject(const Fmt: string; Args : Array of const; AObject: TObject): Integer; overload;
+    function AddPair(const AName, AValue: string): TStrings; overload;
+    function AddPair(const AName, AValue: string; AObject: TObject): TStrings; overload;
     procedure Append(const S: string);
     procedure AddStrings(TheStrings: TStrings); overload; virtual;
     procedure AddStrings(TheStrings: TStrings; ClearFirst : Boolean); overload;
diff --git a/rtl/objpas/classes/stringl.inc b/rtl/objpas/classes/stringl.inc
index 907c115..f32769a 100644
--- a/rtl/objpas/classes/stringl.inc
+++ b/rtl/objpas/classes/stringl.inc
@@ -758,6 +758,17 @@ begin
   Result:=AddObject(Format(Fmt,Args),AObject);
 end;
 
+function TStrings.AddPair(const AName, AValue: string): TStrings;
+begin
+  Result := Self;
+  Add(Concat(AName, NameValueSeparator, AValue));
+end;
+
+function TStrings.AddPair(const AName, AValue: string; AObject: TObject): TStrings;
+begin
+  Result := Self;
+  AddObject(Concat(AName, NameValueSeparator, AValue), AObject);
+end;
 
 Procedure TStrings.Append(const S: string);
 
-- 
2.7.4

Bart Broersma

2018-03-21 11:07

reporter   ~0107313

Why not let the AddPair(string, string) call (inline) AddPair(string, string, nil)?

Michael Van Canneyt

2018-03-21 11:30

administrator   ~0107315

Applied, modified as Bart suggested.

silvioprog

2018-03-21 18:16

reporter   ~0107324

The long signature of AddPair is not marked as inline in Delphi wiki, but since FPC can inline it (I checked the generated assembly and it was really inlined) we can leave it as inline to get more performance. For embedded systems (AVR, ARM, STM...) the final hex/binary will grow if the programmer use many AddPair in his code, however, in this case, the programmer could disable the inline feature by compiler options.

The for applying the patch!

Issue History

Date Modified Username Field Change
2018-03-21 01:06 silvioprog New Issue
2018-03-21 01:06 silvioprog File Added: 0001-Patch-from-silvioprog-to-implement-TStrings.AddPair-.patch
2018-03-21 10:49 Michael Van Canneyt Assigned To => Michael Van Canneyt
2018-03-21 10:49 Michael Van Canneyt Status new => assigned
2018-03-21 11:07 Bart Broersma Note Added: 0107313
2018-03-21 11:30 Michael Van Canneyt Fixed in Revision => 38587
2018-03-21 11:30 Michael Van Canneyt Note Added: 0107315
2018-03-21 11:30 Michael Van Canneyt Status assigned => resolved
2018-03-21 11:30 Michael Van Canneyt Fixed in Version => 3.1.1
2018-03-21 11:30 Michael Van Canneyt Resolution open => fixed
2018-03-21 11:30 Michael Van Canneyt Target Version => 3.2.0
2018-03-21 18:16 silvioprog Note Added: 0107324
2018-03-21 18:16 silvioprog Status resolved => closed