View Issue Details

IDProjectCategoryView StatusLast Update
0035614LazarusTAChartpublic2019-06-12 22:23
ReporterMarcin WiazowskiAssigned Towp 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionreopened 
Product Version2.1 (SVN)Product Build61262 
Target VersionFixed in Version 
Summary0035614: TAChart: some tiny optimization
DescriptionI'm attaching a tiny patch, which changes some

  "with FOwner as TCustomChartSource do"

to

  "with TCustomChartSource(FOwner) do"



This is an optimization, because "TCustomChartSource(FOwner)" does not generate any code, while the "as" operator generates a call to "fpc_do_as" - which internally iterates through object's virtual method tables, to verify the inheritance.

The code can be changed safely, because FOwner's type is checked one line above.
TagsNo tags attached.
Fixed in Revision61263, 61269
LazTarget-
WidgetsetWin32/Win64
Attached Files
  • patch.diff (490 bytes)
    Index: components/tachart/tacustomsource.pas
    ===================================================================
    --- components/tachart/tacustomsource.pas	(revision 61262)
    +++ components/tachart/tacustomsource.pas	(working copy)
    @@ -436,7 +436,7 @@
     procedure TChartAxisIntervalParams.Changed;
     begin
       if not (FOwner is TCustomChartSource) then exit;
    -  with FOwner as TCustomChartSource do begin
    +  with TCustomChartSource(FOwner) do begin
         BeginUpdate;
         EndUpdate;
       end;
    
    patch.diff (490 bytes)

Relationships

related to 0035704 closedwp TAChart: trivial mistake in "tools" demo 

Activities

Marcin Wiazowski

2019-05-21 21:24

reporter  

patch.diff (490 bytes)
Index: components/tachart/tacustomsource.pas
===================================================================
--- components/tachart/tacustomsource.pas	(revision 61262)
+++ components/tachart/tacustomsource.pas	(working copy)
@@ -436,7 +436,7 @@
 procedure TChartAxisIntervalParams.Changed;
 begin
   if not (FOwner is TCustomChartSource) then exit;
-  with FOwner as TCustomChartSource do begin
+  with TCustomChartSource(FOwner) do begin
     BeginUpdate;
     EndUpdate;
   end;
patch.diff (490 bytes)

wp

2019-05-22 00:28

developer   ~0116314

Thanks. Extended fix to all duplicate type checks.

Marcin Wiazowski

2019-05-22 01:39

reporter   ~0116319

Very nice!



It seems that one problem has been introduced: typecasting an **interface** as another interface must use "as" (some info in http://docwiki.embarcadero.com/RADStudio/Rio/en/Using_the_as_Operator_with_Interfaces). Try this: load "tachart\demo\html", and change TBasicDrawer.HtmlTextExtent() to:

  function TBasicDrawer.HtmlTextExtent(const AText: String): TPoint;
  var
    IDrawer0: IUnknown;
    IDrawer: IChartDrawer;
  begin
    IDrawer0 := Self as IUnknown;
    if not (IDrawer0 is IChartDrawer) then exit;
    IDrawer := IDrawer0 as IChartDrawer;
// IDrawer := IChartDrawer(IDrawer0);
    with THtmlAnalyzer.Create(IDrawer) do
      try
        Result := TextExtent(AText);
      finally
        Free;
      end;
  end;

This works properly. Now uncomment the line that is commented out, and remove the line above. Now the code crashes.



This probably means, that changes in tadiagramdrawing.pas should be reverted (although I couldn't find a way of executing this code, so I haven't verified this).

wp

2019-05-22 12:04

developer   ~0116330

Thanks.

Marcin Wiazowski

2019-05-22 18:05

reporter   ~0116344

It's ok now. Thanks.

Issue History

Date Modified Username Field Change
2019-05-21 21:24 Marcin Wiazowski New Issue
2019-05-21 21:24 Marcin Wiazowski File Added: patch.diff
2019-05-22 00:28 wp Assigned To => wp
2019-05-22 00:28 wp Status new => resolved
2019-05-22 00:28 wp Resolution open => fixed
2019-05-22 00:28 wp Fixed in Revision => 61263
2019-05-22 00:28 wp LazTarget => -
2019-05-22 00:28 wp Widgetset Win32/Win64 => Win32/Win64
2019-05-22 00:28 wp Note Added: 0116314
2019-05-22 01:39 Marcin Wiazowski Status resolved => assigned
2019-05-22 01:39 Marcin Wiazowski Resolution fixed => reopened
2019-05-22 01:39 Marcin Wiazowski Note Added: 0116319
2019-05-22 12:04 wp Status assigned => resolved
2019-05-22 12:04 wp Fixed in Revision 61263 => 61263, 61269
2019-05-22 12:04 wp Widgetset Win32/Win64 => Win32/Win64
2019-05-22 12:04 wp Note Added: 0116330
2019-05-22 18:05 Marcin Wiazowski Note Added: 0116344
2019-05-22 18:05 Marcin Wiazowski Status resolved => closed
2019-06-12 22:23 wp Relationship added related to 0035704