Here's something I toyed with, to avoid the overhead of the RTTI invoke method. Essentially reduces overhead to two virtual calls per invokation.
var widget: TWidget; f: RIFunc; // reference to function(const Instance): string; name: string; begin widget := ... f := RI.PropGetter('Name'); name := f(widget); WriteLn(name); end;
Can do regular methods too of course.
Anyway yea generics can be useful for more than containers :-)
Here's something I toyed with, to avoid the overhead of the RTTI invoke method. Essentially reduces overhead to two virtual calls per invokation.
ReplyDeletevar
widget: TWidget;
f: RIFunc; // reference to function(const Instance): string;
name: string;
begin
widget := ...
f := RI.PropGetter('Name');
name := f(widget);
WriteLn(name);
end;
Can do regular methods too of course.
Anyway yea generics can be useful for more than containers :-)
Generics are great for aggregation too.
ReplyDelete