Recent

Author Topic: WSRegisterClass apparent inefficiency  (Read 940 times)

BrunoK

  • Sr. Member
  • ****
  • Posts: 452
  • Retired programmer
WSRegisterClass apparent inefficiency
« on: June 17, 2020, 04:43:03 pm »
While testing issue https://bugs.freepascal.org/view.php?id=37216 I fell on TControl.WSRegisterClass  and TWinControl.WSRegisterClass that are called repeatedly via TLCLComponent.NewInstance when creating a TLCLComponent descendant instance.

Taking a TControl as TLCLComponent descendant, is there a reason to not mark the class as registered the first time TControl.WSRegisterClass is called ?

Using RegisterControl (in \lcl\widgetset\wscontrols.pp) as a model, I apparently successfully managed to skip lots of code repetition at runtime, specifically the repeated calls to RegisterPropertyToSkip that need list scanning every time a NewInstance  is created.

The code I have now for TControl and TWinControl WSRegisterClass are the following ones :
Code: Pascal  [Select][+][-]
  1. class procedure TControl.WSRegisterClass;
  2. const
  3.   Registered : boolean = False;
  4. begin
  5.   if Registered then
  6.     Exit;
  7.   inherited WSRegisterClass;
  8.   RegisterControl;
  9.   RegisterPropertyToSkip(TControl, 'AlignWithMargins', 'VCL compatibility property', '');
  10.   RegisterPropertyToSkip(TControl, 'Ctl3D',            'VCL compatibility property', '');
  11.   RegisterPropertyToSkip(TControl, 'ParentCtl3D',      'VCL compatibility property', '');
  12.   RegisterPropertyToSkip(TControl, 'IsControl',        'VCL compatibility property', '');
  13.   RegisterPropertyToSkip(TControl, 'DesignSize',       'VCL compatibility property', '');
  14.   RegisterPropertyToSkip(TControl, 'ExplicitLeft',     'VCL compatibility property', '');
  15.   RegisterPropertyToSkip(TControl, 'ExplicitHeight',   'VCL compatibility property', '');
  16.   RegisterPropertyToSkip(TControl, 'ExplicitTop',      'VCL compatibility property', '');
  17.   RegisterPropertyToSkip(TControl, 'ExplicitWidth',    'VCL compatibility property', '');
  18.   Registered := True;
  19. end;
Code: Pascal  [Select][+][-]
  1. class procedure TWinControl.WSRegisterClass;
  2. const
  3.   Registered : boolean = False;
  4. begin
  5.   if Registered then
  6.     Exit;
  7.   inherited WSRegisterClass;
  8.   RegisterWinControl;
  9.   RegisterPropertyToSkip(TWinControl, 'ParentDoubleBuffered', 'VCL compatibility property', '');
  10.   RegisterPropertyToSkip(TWinControl, 'ImeMode', 'VCL compatibility property', '');
  11.   RegisterPropertyToSkip(TWinControl, 'ImeName', 'VCL compatibility property', '');
  12.   Registered := True;
  13. end;
I rebuild lazarus and every thing works correctly.

Is there an obvious reason that it would create troubles ?

Lazarus quite recent trunk (+/- changes regarding TScrollBar, IntitalSetupDialog, Options.Environment options).  FPC 3.0.4 (the mac os one) from svn + some mods.
Windows 10 Pro x64 (v. 1903 / 18362.418) and for occasional Linux tests, Manjaro (QT5 and GTK2)


jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: WSRegisterClass apparent inefficiency
« Reply #1 on: June 19, 2020, 12:41:48 am »
I would go as far as implementing an overloaded version of that...

RegisterPropertyToSkip(TControl, ArrayofItems , 'VCL_...….','');
The only true wisdom is knowing you know nothing

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: WSRegisterClass apparent inefficiency
« Reply #2 on: June 19, 2020, 01:12:41 am »
I would not expect this to be a problem.
And I would say something should be done.

Just a few personal thoughts:
- I am not sure, if we need to (or should) check twice. (In WSRegisterClass and in Register<ClassName>).

- Maybe the RegisterPropertyToSkip can be moved to Register<ClassName>. Though the purpose of that unit is different....

- Or if Register<ClassName> is only called by WSRegisterClass, then a check in WSRegisterClass  would be enough (but then they all need to move, to keep it from getting confusing....)


 

TinyPortal © 2005-2018