Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: Optimizing non-alphanumeric method calls

by LanX (Saint)
on Sep 27, 2015 at 19:12 UTC ( [id://1143167]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Optimizing non-alphanumeric method calls
in thread Optimizing non-alphanumeric method calls

>  but it cannot be used, unfortunately, on chained method calls, such as $obj->$method_1->$method_2, unless the result returned by $obj->$method_1 is stored somewhere, which I guess it may slow things down quite a bit. 

I'm not sure what you mean, $c_method isn't different in this respect to the other approaches you have proposed.

For chained method calls you need to return the object in intermediate calls, no matter which approach you use.

Maybe you should show us some real code to make things clearer.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^4: Optimizing non-alphanumeric method calls
by trizen (Hermit) on Sep 27, 2015 at 19:42 UTC

    Here is a real code translation of "(1+7)/4":

    use constant NUM23343688 => Sidef::Types::Number::Number->new('1'); use constant NUM25174720 => Sidef::Types::Number::Number->new('7'); use constant NUM24946728 => Sidef::Types::Number::Number->new('4'); ((main::NUM23343688)->${\'+'}(main::NUM25174720))->${\'/'}(main::NUM24 +946728);

    Note that currently I'm using the reference-dereference technique for calling non-alphanumeric methods. What I'm really looking for, it's an way to avoid this inefficient approach without any other trade-offs.

      Interesting, I wasn't aware of this trick to fool the parser. (I suppose the special symbols are put directly into the stash of the class)

      Using _add instead of + as method name should make it easier.

      But replacing ${\'+'} with $_add holding the code ref is the fastest.

      Problems with chains do not exist.

      Btw: Are you aware that Perl supports operater overloading?

      (This won't be faster, rather slower but more readable)

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

Re^4: Optimizing non-alphanumeric method calls
by BillKSmith (Monsignor) on Sep 27, 2015 at 20:10 UTC
    Maybe you should show us some real code to make things clearer.

    trizen has done what we ask of nearly every first-time poster. He has prepared a complete executable example. I feel it would be far better to suggest improvements to the example than to discourage this style of question.

    Bill
      Nope, his reply to my supposed "discouragement" was much better.

      But your contribution so far is on another level...

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1143167]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found