Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2001:
[Freeciv-Dev] Re: [Patch] Cleanup regarding {city,unit}_owner
Home

[Freeciv-Dev] Re: [Patch] Cleanup regarding {city,unit}_owner

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Trent Piepho <xyzzy@xxxxxxxxxxxxx>
Cc: freeciv development list <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: [Patch] Cleanup regarding {city,unit}_owner
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 24 Aug 2001 09:47:59 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Fri, Aug 24, 2001 at 12:23:27AM -0700, Trent Piepho wrote:
> On Fri, 24 Aug 2001, Raimar Falke wrote:
> >  4) after this if {unit,city}_owner() still takes to much time make a
> >  macro/inline function out of it
> >  5) if somebody sends me a patch for making owner field a pointer and
> >  this is considerable faster than 4) I will apply it. In this patch
> >  {unit,city}_owner() would probably end up as macros/inline functions
> >  (but are still lower cased)
> 
> I thought you wanted to get rid of places id were used instead of pointers?

As function arguments: yes, this is an interface issue. As a member of
a struct: this is only a performance issue. So this depends on a
possible performance improvement. It may possible that there are only
a small number of calls to *_owner or switching to pointers will only
give us a 0.1% improvement. An abstraction is first need for such
testing. The *_owner methods are there and provide such
abstraction. They make it possible to switch to other methods of
getting a player pointer.

> Why don't you make unit_x(), unit_y(), unit_homecity(), etc.  for
> every other member of the structure?  Why is owner special?

If a unit's homecity is needed often and it will be converted most of
the times to a city pointer I would consider the introduction of
unit_homecity() an improvement. This is just clearity, less writing
and abstraction.

$ grep -Ir -- "->homecity" .|wc -l
     79
$ grep -Ir -- "->homecity" .|grep find_city_by_id |wc -l
     37

This looks like a no issue compared to:

$ grep -Ir -- "city_owner" .|wc -l
    134
$ grep -Ir -- "unit_owner" .|wc -l
    155

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Python is executable pseudocode. Perl is executable line noise"
    -- Bruce Eckel


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