Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2001:
[Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand
Home

[Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Markus Linnala <maage@xxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 20 Aug 2001 14:27:26 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Mon, Aug 20, 2001 at 11:06:07AM +0300, Markus Linnala wrote:
> 
> I propose we change genlist iterator macros as follows. This
> allows you two things. You can get rid of extra function call.
> And you can also inline call. As patch follows.
> 
> genlist_iterator_init is called more than 99% by these macros.
> Therefore we should optimize fast track.

find_genlist_position() does the right thing for -1. So there is only
the overhead of one (find_genlist_position) function call.

> +static inline void genlist_iterator_init_m1(struct genlist_iterator *iter,
> +                                         struct genlist *pgenlist);

This method should have tail in its name.

> +static inline void genlist_iterator_init_0(struct genlist_iterator *iter,
> +                                        struct genlist *pgenlist);

And this one head.

> Same kind of optimization goes to get_player. It is not used
> everywhere by the way.
> 
> Now we do something like that.
> 
> void function_xx(struct player *pplayer, int x, int y) {
>         int player_no = pplayer->player_no;
>         struct tile *ptile = map_get_player_tile(x, y, player_no);
> ....
> }
> struct player_tile *map_get_player_tile(int x, int y, int playerid)
> {
>   if(y<0 || y>=map.ysize) {
>     freelog(LOG_ERROR, "Trying to get nonexistant tile at %i,%i", x,y);
>     return get_player(playerid)->private_map
>       + map_adjust_x(x)+map_adjust_y(y)*map.xsize;
>   } else
>     return get_player(playerid)->private_map
>       + map_adjust_x(x)+y*map.xsize;
> }
> 
> And at map_get_player_tile, we find out again what is struct
> player. Almost all use of get_player is like this. First we have
> 'struct player', then we get player_no and in next instant we
> get 'struct player' again by player_no. Seems waste of work to
> me.

It is. I would like a discussion what is preferred: id or pointer. If
one type is selected we can start our crusade.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "I haven't lost my mind - it's backed up on tape somewhere."


[Prev in Thread] Current Thread [Next in Thread]