Using function pointers is seldom a good idea.
Also what will you do if the function calls take different parameters?


On Mon, Jul 14, 2014 at 9:17 AM, Marko Lindqvist <
no-reply.invalid-addr...@gna.org> wrote:

> URL:
>   <http://gna.org/patch/?4949>
>
>                  Summary: [Metaticket] Get rid of massive switch-cases
>                  Project: Freeciv
>             Submitted by: cazfi
>             Submitted on: Mon 14 Jul 2014 11:17:00 AM EEST
>                 Category: None
>                 Priority: 5 - Normal
>                   Status: None
>                  Privacy: Public
>              Assigned to: None
>         Originator Email:
>              Open/Closed: Open
>          Discussion Lock: Any
>          Planned Release:
>
>     _______________________________________________________
>
> Details:
>
> To at least open a ticket of something I've long wanted to do...
>
> We have a couple of switch - case constructs with a lot of cases (packet
> handling has a case for each packet number, ai effect evaluation for each
> effect type). While I haven't measured how much that affects our overall
> performance, checking against each case in often called functions certainly
> gives us some performance hit (I don't think any compiler can make major
> optimizations on this - feel free to correct me).
>
> My plan is to investigate possibilities to build function arrays, so that
> what
> currently is an case would be array index:
>
> switch (var) {
> case 0:
>   func0();
>   break;
> case 1:
>   func1();
>   break;
> case 2:
>   func2();
>   break
> ...
> }
>
> ->
>
> funcs[var]();
>
>
>
>
>
>     _______________________________________________________
>
> Reply to this item at:
>
>   <http://gna.org/patch/?4949>
>
> _______________________________________________
>   Message sent via/by Gna!
>   http://gna.org/
>
>
> _______________________________________________
> Freeciv-dev mailing list
> Freeciv-dev@gna.org
> https://mail.gna.org/listinfo/freeciv-dev
>



-- 
Vasco Alexandre da Silva Costa
PhD Student at Department of Information Systems and Computer Science
IST/Technical University of Lisbon
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to