forked from github/server
make findunitr be O(1) instead of O(#r->units)
This commit is contained in:
parent
5faf642b9c
commit
60111282b3
2 changed files with 12 additions and 15 deletions
|
@ -2640,8 +2640,9 @@ static void steal_cmd(unit * u, struct order *ord, request ** stealorders)
|
|||
return;
|
||||
}
|
||||
id = read_unitid(u->faction, r);
|
||||
u2 = findunitr(r, id);
|
||||
|
||||
if (id>0) {
|
||||
u2 = findunitr(r, id);
|
||||
}
|
||||
if (u2 && u2->region == u->region) {
|
||||
f = u2->faction;
|
||||
}
|
||||
|
|
|
@ -97,19 +97,6 @@ attrib_type at_creator = {
|
|||
/* Rest ist NULL; temporaeres, nicht alterndes Attribut */
|
||||
};
|
||||
|
||||
unit *findunitr(const region * r, int n)
|
||||
{
|
||||
unit *u;
|
||||
|
||||
/* findunit regional! */
|
||||
|
||||
for (u = r->units; u; u = u->next)
|
||||
if (u->no == n)
|
||||
return u;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unit *findunit(int n)
|
||||
{
|
||||
if (n <= 0) {
|
||||
|
@ -118,6 +105,15 @@ unit *findunit(int n)
|
|||
return ufindhash(n);
|
||||
}
|
||||
|
||||
unit *findunitr(const region * r, int n)
|
||||
{
|
||||
unit *u;
|
||||
/* findunit regional! */
|
||||
assert(n>0);
|
||||
u = ufindhash(n);
|
||||
return (u && u->region==r)?u:0;
|
||||
}
|
||||
|
||||
unit *findunitg(int n, const region * hint)
|
||||
{
|
||||
|
||||
|
|
Loading…
Reference in a new issue