Update of patch #4940 (project freeciv):
Status: In Progress => Ready For Test
Follow-up Comment #5:
Thanks a lot for reminding me about performance: figuring out how to do this
with the lowest call count, least stack usage, and fewest lines of code led to
interesting investigations into C.
The new patch exposes universal_fulfills_requirement() so that all the
requirement_fulfilled_by_foo() functions can be replaced with macros, passes
the universal as a pointer, and maintains a static array of the item_found
functions indexed by universal kind, initialised in game_init().
Adding support for a new kind now requires writing the item_found function,
and then adding 4 lines of source (a savings from the 24 used on trunk). I've
added back some asserts: null requirement vectors are fine (iterating over
NULL loops 0 times), and if we found a req during an iteration, that req
exists, but it is worth verifying that a function to find items exists, and
that there is an item to find. Note that actually passing callbacks (rather
than maintaining the array) doesn't reduce the code requirement: while one
doesn't need the line populating the array, one does need a declaration to be
available to the macro, so no net savings (and much wider exposure of
implementation details over the codebase). It would be possible to reduce to
two lines of code with a MACRO to generate the macros, but I thought that
would get closer to unreadable, so didn't go that far.
There is an incidental textual dependency on patch #4939, but not a functional
one (this patch removes or replaces 6 lines of code changed in that patch().
Additional Item Attachment:
File name: rewrite-universal_fulfills_requirement+faster.patch Size:8 KB
Reply to this item at:
Message sent via/by Gna!
Freeciv-dev mailing list