c++ refactoring of function

56 views
Skip to first unread message

bsjkb

unread,
Jan 20, 2018, 10:42:02 AM1/20/18
to ISO C++ Standard - Discussion

I have an array of numbers, for example: 1,2,3,4,5...,10

For every item the following function is called:

    do
     {
      if (..)
        {
         return_val= performsomething (parm1,parm2..parm5);
        }
     }

The function performsomething() is written like below:

    performsomething (x1,x2,...)
    {
     if (A_req?)
      {
       performA();
      }
     else if (B_req?)
      {
      performB();
      }
    }

Now, if it is seen closely, for every item the function performsomething() is getting called.

I want to avoid the performance overhead of these many function calls. I want to refactor the method performsomething() like it will check the conditions A_req? or B_req?. Accordingly, it will call performA() or performB(). I want to make performsomething() as 'inline' and call the underlying functions as needed.

Please help me how to code efficiently to achieve the above requirement .!.

Todd Fleming

unread,
Jan 20, 2018, 11:19:47 AM1/20/18
to ISO C++ Standard - Discussion, shamik...@gmail.com

On Saturday, January 20, 2018 at 10:42:02 AM UTC-5, bsjkb wrote:

Please help me how to code efficiently to achieve the above requirement .!.


This forum is not for these types of questions.

meta: It looks like the meaning of "This group is for discussion and Q&A about the current ISO C++ standard" is impenetrable for new users and non-native speakers.

Todd

Richard Hodges

unread,
Jan 20, 2018, 11:47:07 AM1/20/18
to std-dis...@isocpp.org
meta: It looks like the meaning of "This group is for discussion and Q&A about the current ISO C++ standard" is impenetrable for new users and non-native speakers.

I think in fairness "discussion and Q&A about the current ISO C++ standard" is a somewhat ambiguous term.

Shamik: suggest you post your question on stacko verflow. Although you'll want to flesh it out into a compilable snippet if you are to avoid being flamed by the somewhat merciless stack overflow community.



--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+unsubscribe@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.

Yubin Ruan

unread,
Jan 20, 2018, 6:18:46 PM1/20/18
to std-dis...@isocpp.org
I don't really understand your question totally, but do you want something
like computed goto? If so, see [1][2].

[1]: https://eli.thegreenplace.net/2012/07/12/computed-goto-for-efficient-dispatch-tables
[2]: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html

--
Yubin

Yubin Ruan

unread,
Jan 20, 2018, 6:19:51 PM1/20/18
to std-dis...@isocpp.org
On Sat, Jan 20, 2018 at 08:19:47AM -0800, Todd Fleming wrote:
>
> On Saturday, January 20, 2018 at 10:42:02 AM UTC-5, bsjkb wrote:
> >
> > Please help me how to code efficiently to achieve the above requirement .!.
> >
>
> This forum is not for these types of questions.

Does isocpp.org host any lists for this?

--
Yubin

Thiago Macieira

unread,
Jan 21, 2018, 12:47:46 PM1/21/18
to std-dis...@isocpp.org
No.

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center



Thiago Macieira

unread,
Jan 21, 2018, 12:48:41 PM1/21/18
to std-dis...@isocpp.org
On Sunday, 21 January 2018 03:18:21 PST Yubin Ruan wrote:
> I don't really understand your question totally, but do you want something
> like computed goto? If so, see [1][2].
>
> [1]:
> https://eli.thegreenplace.net/2012/07/12/computed-goto-for-efficient-dispat
> ch-tables [2]: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html

GCC's computed gotos aren't completely implemented in C++. The alternate
syntax at the bottom of the page will fail to compile.
Reply all
Reply to author
Forward
0 new messages