[Freeciv-Dev] Re: {gen,spec,sort}list stuff
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
At 05:23 PM 01/08/28 +0200, Raimar Falke wrote:
>On Tue, Aug 28, 2001 at 10:27:28AM -0400, Justin Moore wrote:
>>
>> > > done at the end, so there are potential inconsistancies. The macros
>> > > (essentially) do this:
>> > >
>> > > while(ITERATOR_PTR(X)) {
>> > > ITERATOR_NEXT(X);
>> > > /* Do stuff */
>> > > }
>> >
>> > No. It does:
>> >
>> > for(; ITERATOR_PTR(myiter);) {
>> > var=(atype *)ITERATOR_PTR(myiter);
>> > ITERATOR_NEXT(myiter);
>> > /* Do stuff */
>> > }
>> >
>> > So the loop body (if it doesn't look at myiter) will see in the first
>> > pass the first element.
>>
>> Yes, I know. Ok, I left out the variable assignment; I assumed people
>> knew the assignment happened along with the ITERATOR_PTR call. I was just
>> using the 'while' construct to visually demonstrate my point about where
>> the iterator is advanced.
>
>> There are places where the iterator is used or passed as a variable
>> to another function. When this is done inside of a macro-based loop
>> it might not yield the right results.
>
>Now I see. I consider this broken or at least very ugly.
You may want to be a little careful around here. The list types 1&2 below
are probably indicative of techniques where you advance the list to get the
next position before you delete the element inside the list and so if not
careful would also lose the iteration thread.
With the saved pointer you just continue merrily.
This will likely cause a number of complications with sorted array lists
that do slot recovery on every deletion as I think Justin found.
These are valid techniques for the current GENLIST flavour, but may not
tranfer easily to others and may not be easily spotted.
So use some caution ...
>> In a bit I'm going to change the macro declaration and see what kind
>> of effect (if any) it has on a game. If the code is robust enough
>> and correct, it shouldn't matter. But we'll see. :)
>>
>> > > 1. Lists that rely heavily on iterators and do nasty things in the
middle
>> > > of iterating such as remove elements from the list (often based on
>> > > the contents of the iterator).
>> > > 2. Lists that occasionally remove items during iteration, but for
the most
>> > > part are constant.
Cheers,
RossW
- [Freeciv-Dev] Re: {gen,spec,sort}list stuff, (continued)
- [Freeciv-Dev] Re: {gen,spec,sort}list stuff, Justin Moore, 2001/08/28
- [Freeciv-Dev] Re: {gen,spec,sort}list stuff, Raimar Falke, 2001/08/28
- [Freeciv-Dev] Re: {gen,spec,sort}list stuff, Justin Moore, 2001/08/28
- [Freeciv-Dev] Re: {gen,spec,sort}list stuff, Raimar Falke, 2001/08/28
- [Freeciv-Dev] Re: {gen,spec,sort}list stuff, Justin Moore, 2001/08/29
- [Freeciv-Dev] Re: {gen,spec,sort}list stuff, Raimar Falke, 2001/08/30
- [Freeciv-Dev] Re: {gen,spec,sort}list stuff, Justin Moore, 2001/08/30
- [Freeciv-Dev] Re: {gen,spec,sort}list stuff, Raimar Falke, 2001/08/30
- [Freeciv-Dev] Re: [PATCH] Re: {gen,spec,sort}list stuff, Justin Moore, 2001/08/31
- [Freeciv-Dev] Re: [PATCH] Re: {gen,spec,sort}list stuff, Raimar Falke, 2001/08/31
- [Freeciv-Dev] Re: {gen,spec,sort}list stuff,
Ross W. Wetmore <=
- [Freeciv-Dev] Re: {gen,spec,sort}list stuff, Raimar Falke, 2001/08/29
|
|